本文整理了Java中javax.swing.JTextField.getGraphics()
方法的一些代码示例,展示了JTextField.getGraphics()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JTextField.getGraphics()
方法的具体详情如下:
包路径:javax.swing.JTextField
类名称:JTextField
方法名:getGraphics
暂无
代码示例来源:origin: org.opentcs.thirdparty.jhotdraw/jhotdraw
protected void updateWidget() {
Font font = editedFigure.getFont();
font = font.deriveFont(font.getStyle(), (float) (editedFigure.getFontSize() * view.getScaleFactor()));
textField.setFont(font);
textField.setForeground(editedFigure.getTextColor());
textField.setBackground(editedFigure.getFillColor());
Rectangle2D.Double fDrawBounds = editedFigure.getBounds();
Point2D.Double fDrawLoc = new Point2D.Double(fDrawBounds.getX(), fDrawBounds.getY());
if (editedFigure.get(TRANSFORM) != null) {
editedFigure.get(TRANSFORM).transform(fDrawLoc, fDrawLoc);
}
Point fViewLoc = view.drawingToView(fDrawLoc);
Rectangle fViewBounds = view.drawingToView(fDrawBounds);
fViewBounds.x = fViewLoc.x;
fViewBounds.y = fViewLoc.y;
Dimension tfDim = textField.getPreferredSize();
Insets tfInsets = textField.getInsets();
float fontBaseline = textField.getGraphics().getFontMetrics(font).getMaxAscent();
double fBaseline = editedFigure.getBaseline() * view.getScaleFactor();
textField.setBounds(
fViewBounds.x - tfInsets.left,
fViewBounds.y - tfInsets.top - (int) (fontBaseline - fBaseline),
Math.max(fViewBounds.width + tfInsets.left + tfInsets.right, tfDim.width),
Math.max(fViewBounds.height + tfInsets.top + tfInsets.bottom, tfDim.height)
);
}
代码示例来源:origin: atarw/material-ui-swing
private void changeColorOnFocus(boolean hasFocus) {
JTextField c = (JTextField) getComponent();
/*c.setSelectionColor(hasFocus ? activeBackground : inactiveBackground);
c.setForeground(hasFocus ? activeForeground : inactiveForeground);
c.setSelectedTextColor(hasFocus ? activeForeground : inactiveForeground);*/
if(hasFocus && (activeBackground != null) && (activeForeground != null)){
c.setSelectionColor(activeBackground);
c.setForeground(activeForeground);
c.setSelectedTextColor(activeForeground);
}
if(!hasFocus && (inactiveBackground != null) && (inactiveForeground != null)){
c.setSelectionColor(inactiveBackground);
c.setForeground(inactiveForeground);
c.setSelectedTextColor(inactiveForeground);
}
c.paint(c.getGraphics());
}
内容来源于网络,如有侵权,请联系作者删除!