javax.swing.JTextField.getGraphics()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(2.2k)|赞(0)|评价(0)|浏览(108)

本文整理了Java中javax.swing.JTextField.getGraphics()方法的一些代码示例,展示了JTextField.getGraphics()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JTextField.getGraphics()方法的具体详情如下:
包路径:javax.swing.JTextField
类名称:JTextField
方法名:getGraphics

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());
}

相关文章

JTextField类方法