mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-12 06:57:13 -06:00
TextField: fixed location of placeholder text if paddings are used (e.g. in ComboBox) (for commit a9dcf09d13)
This commit is contained in:
@@ -157,7 +157,7 @@ public class FlatTextFieldUI
|
|||||||
@Override
|
@Override
|
||||||
protected void paintSafely( Graphics g ) {
|
protected void paintSafely( Graphics g ) {
|
||||||
paintBackground( g, getComponent(), isIntelliJTheme, focusedBackground );
|
paintBackground( g, getComponent(), isIntelliJTheme, focusedBackground );
|
||||||
paintPlaceholder( g, getComponent(), placeholderForeground );
|
paintPlaceholder( g );
|
||||||
|
|
||||||
super.paintSafely( HiDPIUtils.createGraphicsTextYCorrection( (Graphics2D) g ) );
|
super.paintSafely( HiDPIUtils.createGraphicsTextYCorrection( (Graphics2D) g ) );
|
||||||
}
|
}
|
||||||
@@ -213,7 +213,9 @@ public class FlatTextFieldUI
|
|||||||
return background;
|
return background;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void paintPlaceholder( Graphics g, JTextComponent c, Color placeholderForeground ) {
|
protected void paintPlaceholder( Graphics g ) {
|
||||||
|
JTextComponent c = getComponent();
|
||||||
|
|
||||||
// check whether text component is empty
|
// check whether text component is empty
|
||||||
if( c.getDocument().getLength() > 0 )
|
if( c.getDocument().getLength() > 0 )
|
||||||
return;
|
return;
|
||||||
@@ -228,16 +230,14 @@ public class FlatTextFieldUI
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
// compute placeholder location
|
// compute placeholder location
|
||||||
Insets insets = c.getInsets();
|
Rectangle r = getVisibleEditorRect();
|
||||||
FontMetrics fm = c.getFontMetrics( c.getFont() );
|
FontMetrics fm = c.getFontMetrics( c.getFont() );
|
||||||
int x = insets.left;
|
int y = r.y + fm.getAscent() + ((r.height - fm.getHeight()) / 2);
|
||||||
int y = insets.top + fm.getAscent() + ((c.getHeight() - insets.top - insets.bottom - fm.getHeight()) / 2);
|
|
||||||
|
|
||||||
// paint placeholder
|
// paint placeholder
|
||||||
g.setColor( placeholderForeground );
|
g.setColor( placeholderForeground );
|
||||||
String clippedPlaceholder = JavaCompatibility.getClippedString( jc, fm,
|
String clippedPlaceholder = JavaCompatibility.getClippedString( c, fm, (String) placeholder, r.width );
|
||||||
(String) placeholder, c.getWidth() - insets.left - insets.right );
|
FlatUIUtils.drawString( c, g, clippedPlaceholder, r.x, y );
|
||||||
FlatUIUtils.drawString( c, g, clippedPlaceholder, x, y );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user