Java Code Examples for javax.swing.text.JTextComponent#getWidth()

The following examples show how to use javax.swing.text.JTextComponent#getWidth() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MaterialComponentField.java    From material-ui-swing with MIT License 6 votes vote down vote up
protected void paintLine(Graphics graphics) {
    if (graphics == null) {
        return;
    }
    JTextComponent c = getComponent();

    if (drawLine) {
        int x = c.getInsets().left;
        int y = c.getInsets().top;
        int w = c.getWidth() - c.getInsets().left - c.getInsets().right;
        if(textComponent.isEnabled()){
            graphics.setColor(colorLine);
        }else{
            graphics.setColor(disabledBackground);
        }

        graphics.fillRect(x, c.getHeight() - y, w, 1);
    }
}
 
Example 2
Source File: MainPanel.java    From java-swing-tips with MIT License 6 votes vote down vote up
@Override public void paint(Graphics g, JComponent c) {
  super.paint(g, c);
  if (c instanceof JLayer) {
    JTextComponent tc = (JTextComponent) ((JLayer<?>) c).getView();
    if (!tc.getText().isEmpty()) {
      Graphics2D g2 = (Graphics2D) g.create();
      g2.setPaint(hint.getForeground());
      Insets i = tc.getInsets();
      Dimension d = hint.getPreferredSize();
      int x = tc.getWidth() - i.right - d.width - 2;
      int y = (tc.getHeight() - d.height) / 2;
      SwingUtilities.paintComponent(g2, hint, tc, x, y, d.width, d.height);
      g2.dispose();
    }
  }
}
 
Example 3
Source File: MainPanel.java    From java-swing-tips with MIT License 6 votes vote down vote up
@Override public void paint(Graphics g, JComponent c) {
  super.paint(g, c);
  if (c instanceof JLayer) {
    JTextComponent tc = (JTextComponent) ((JLayer<?>) c).getView();
    if (!tc.getText().isEmpty()) {
      Graphics2D g2 = (Graphics2D) g.create();
      g2.setPaint(hint.getForeground());
      Insets i = tc.getInsets();
      Dimension d = hint.getPreferredSize();
      int x = tc.getWidth() - i.right - d.width - 2;
      int y = (tc.getHeight() - d.height) / 2;
      SwingUtilities.paintComponent(g2, hint, tc, x, y, d.width, d.height);
      g2.dispose();
    }
  }
}
 
Example 4
Source File: FlatPasswordFieldUI.java    From FlatLaf with Apache License 2.0 5 votes vote down vote up
protected void paintCapsLock( Graphics g ) {
	JTextComponent c = getComponent();
	if( !FlatUIUtils.isPermanentFocusOwner( c ) ||
		!Toolkit.getDefaultToolkit().getLockingKeyState( KeyEvent.VK_CAPS_LOCK ) )
	  return;

	int y = (c.getHeight() - capsLockIcon.getIconHeight()) / 2;
	int x = c.getWidth() - capsLockIcon.getIconWidth() - y;
	capsLockIcon.paintIcon( c, g, x, y );
}
 
Example 5
Source File: InternalSourceViewerComponent.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
public Shape paintLayer(Graphics g, int offs0, int offs1,
                    Shape bounds, JTextComponent c, View view) {
    try {
        Rectangle r = c.modelToView(offs0);
        r.x = 0;
        r.width = c.getWidth();
        
        g.setColor(getColor());
        ((Graphics2D)g).fill(r);
        
        return r;
    } catch (BadLocationException ex) {
        return null;
    }
}
 
Example 6
Source File: SeaGlassTextFieldUI.java    From seaglass with Apache License 2.0 5 votes vote down vote up
/**
 * DOCUMENT ME!
 *
 * @return DOCUMENT ME!
 */
protected Rectangle getCancelButtonBounds() {
    JTextComponent c = getComponent();
    final int      x = c.getWidth() - c.getHeight() / 2 - 9;
    final int      y = c.getHeight() / 2 - 8;

    return new Rectangle(x, y, 17, 17);
}
 
Example 7
Source File: DarculaPasswordFieldUI.java    From Darcula with Apache License 2.0 5 votes vote down vote up
@Override
protected void paintBackground(Graphics graphics) {
  Graphics2D g = (Graphics2D)graphics;
  final JTextComponent c = getComponent();
  final Container parent = c.getParent();
  if (parent != null) {
    g.setColor(parent.getBackground());
    g.fillRect(0, 0, c.getWidth(), c.getHeight());
  }
  final Border border = c.getBorder();
  if (border instanceof DarculaTextBorder) {
    g.setColor(c.getBackground());
    final int width = c.getWidth();
    final int height = c.getHeight();
    final Insets i = border.getBorderInsets(c);
    if (c.hasFocus()) {
      final GraphicsConfig config = new GraphicsConfig(g);
      g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE);

      g.fillRoundRect(i.left - 5, i.top - 2, width - i.left - i.right + 10, height - i.top - i.bottom + 6, 5, 5);
      config.restore();
    }
    else {
      g.fillRect(i.left - 5, i.top - 2, width - i.left - i.right + 12, height - i.top - i.bottom + 6);
    }
  } else {
    super.paintBackground(g);
  }
}
 
Example 8
Source File: DarculaTextFieldUI.java    From Darcula with Apache License 2.0 5 votes vote down vote up
protected Rectangle getDrawingRect() {
  final JTextComponent c = getComponent();
  final Insets i = c.getInsets();
  final int x = i.right - 4 - 16;
  final int y = i.top - 3;
  final int w = c.getWidth() - i.left - i.right + 16*2 +7*2  - 5;
  int h = c.getBounds().height - i.top - i.bottom + 4*2 - 3;
  if (h%2==1) h++;
  return new Rectangle(x, y, w, h);
}
 
Example 9
Source File: ModernPasswordFieldUI.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected void paintBackground(Graphics graphics) {
  Graphics2D g = (Graphics2D)graphics;
  final JTextComponent c = getComponent();
  final Container parent = c.getParent();
  if (parent != null) {
    g.setColor(parent.getBackground());
    g.fillRect(0, 0, c.getWidth(), c.getHeight());
  }
  final Border border = c.getBorder();
  if (border instanceof ModernTextBorder) {
    g.setColor(c.getBackground());
    final int width = c.getWidth();
    final int height = c.getHeight();
    final Insets i = border.getBorderInsets(c);
    if (c.hasFocus()) {
      final GraphicsConfig config = new GraphicsConfig(g);
      g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE);

      g.fillRect(i.left - 5, i.top - 2, width - i.left - i.right + 10, height - i.top - i.bottom + 6);
      config.restore();
    }
    else {
      g.fillRect(i.left - 5, i.top - 2, width - i.left - i.right + 12, height - i.top - i.bottom + 6);
    }
  }
  else {
    super.paintBackground(g);
  }
}
 
Example 10
Source File: DarculaPasswordFieldUI.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected void paintBackground(Graphics graphics) {
  Graphics2D g = (Graphics2D)graphics;
  final JTextComponent c = getComponent();
  final Container parent = c.getParent();
  if (parent != null) {
    g.setColor(parent.getBackground());
    g.fillRect(0, 0, c.getWidth(), c.getHeight());
  }
  final Border border = c.getBorder();
  if (border instanceof DarculaTextBorder) {
    g.setColor(c.getBackground());
    final int width = c.getWidth();
    final int height = c.getHeight();
    final Insets i = border.getBorderInsets(c);
    if (c.hasFocus()) {
      final GraphicsConfig config = new GraphicsConfig(g);
      g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE);

      g.fillRoundRect(i.left - 5, i.top - 2, width - i.left - i.right + 10, height - i.top - i.bottom + 6, 5, 5);
      config.restore();
    }
    else {
      g.fillRect(i.left - 5, i.top - 2, width - i.left - i.right + 12, height - i.top - i.bottom + 6);
    }
  } else {
    super.paintBackground(g);
  }
}
 
Example 11
Source File: DarculaTextFieldUI.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected Rectangle getDrawingRect() {
  final JTextComponent c = myTextField;
  final Insets i = c.getInsets();
  final int x = i.right - JBUI.scale(4) - JBUI.scale(16);
  final int y = i.top - JBUI.scale(3);
  final int w = c.getWidth() - (i.right + i.left) + JBUI.scale(16 * 2) + JBUI.scale(7 * 2) - JBUI.scale(5);
  int h = c.getBounds().height - (i.top + i.bottom) + JBUI.scale(4 * 2) - JBUI.scale(3);
  if (h % 2 == 1) h += JBUI.scale(1);
  return new Rectangle(x, y, w, h);
}