Java Code Examples for javax.swing.text.JTextComponent#getHeight()
The following examples show how to use
javax.swing.text.JTextComponent#getHeight() .
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: FlatTextFieldUI.java From FlatLaf with Apache License 2.0 | 6 votes |
static void paintPlaceholder( Graphics g, JTextComponent c, Color placeholderForeground ) { // check whether text component is empty if( c.getDocument().getLength() > 0 ) return; // check for JComboBox Container parent = c.getParent(); JComponent jc = (parent instanceof JComboBox) ? (JComboBox<?>) parent : c; // get placeholder text Object placeholder = jc.getClientProperty( FlatClientProperties.PLACEHOLDER_TEXT ); if( !(placeholder instanceof String) ) return; // compute placeholder location Insets insets = c.getInsets(); FontMetrics fm = c.getFontMetrics( c.getFont() ); int x = insets.left; int y = insets.top + fm.getAscent() + ((c.getHeight() - insets.top - insets.bottom - fm.getHeight()) / 2); // paint placeholder g.setColor( placeholderForeground ); FlatUIUtils.drawString( c, g, (String) placeholder, x, y ); }
Example 2
Source File: HintTextFieldUI.java From gdx-texture-packer-gui with Apache License 2.0 | 6 votes |
@Override protected void paintSafely(Graphics g) { super.paintSafely(g); JTextComponent comp = getComponent(); if (hint != null && comp.getText().length() == 0 && (!(hideOnFocus && comp.hasFocus()))) { if (color != null) { g.setColor(color); } else { g.setColor(comp.getForeground().brighter().brighter().brighter()); } Insets margin = comp.getMargin(); int padding = (comp.getHeight() - comp.getFont().getSize()) / 2; //TODO Apply vertical margin as well g.drawString(hint, margin.left + 2, comp.getHeight() - padding - 1); } }
Example 3
Source File: MainPanel.java From java-swing-tips with MIT License | 6 votes |
@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: MainPanel.java From java-swing-tips with MIT License | 6 votes |
@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 5
Source File: FlatPasswordFieldUI.java From FlatLaf with Apache License 2.0 | 5 votes |
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 6
Source File: HintTextFieldUI.java From azure-devops-intellij with MIT License | 5 votes |
@Override protected void paintSafely(Graphics g) { super.paintSafely(g); JTextComponent component = getComponent(); if (hintText != null && component.getText().length() == 0 && !component.hasFocus()) { g.setColor(JBColor.GRAY); final int fontSize = component.getFont().getSize(); final int padding = (component.getHeight() - fontSize) / 2; final int x = component.getInsets().left; final int y = component.getHeight() - padding - 1; g.drawString(hintText, x, y); } }
Example 7
Source File: SeaGlassTextFieldUI.java From seaglass with Apache License 2.0 | 5 votes |
/** * DOCUMENT ME! * * @return DOCUMENT ME! */ protected Rectangle getFindButtonBounds() { JTextComponent c = getComponent(); final int x = c.getHeight() / 2 - 6; final int y = c.getHeight() / 2 - 6; return new Rectangle(x, y, 22, 17); }
Example 8
Source File: SeaGlassTextFieldUI.java From seaglass with Apache License 2.0 | 5 votes |
/** * 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 9
Source File: DarculaPasswordFieldUI.java From Darcula with Apache License 2.0 | 5 votes |
@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 10
Source File: ModernPasswordFieldUI.java From consulo with Apache License 2.0 | 5 votes |
@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 11
Source File: DarculaPasswordFieldUI.java From consulo with Apache License 2.0 | 5 votes |
@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); } }