From 51d7bc2c372c0c098649e724decc8c730aa2c3e4 Mon Sep 17 00:00:00 2001 From: Karl Tauber Date: Thu, 2 Sep 2021 16:18:53 +0200 Subject: [PATCH] TextField, FormattedTextField, PasswordField and ComboBox: fixed alignment of placeholder text in right-to-left component orientation --- CHANGELOG.md | 2 ++ .../main/java/com/formdev/flatlaf/ui/FlatTextFieldUI.java | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e4c7d432..fc7efe32 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,8 @@ FlatLaf Change Log since FlatLaf 1.3) - OptionPane: Fixed `OptionPane.sameSizeButtons`, which did not work as expected when setting to `false`. +- TextField, FormattedTextField, PasswordField and ComboBox: Fixed alignment of + placeholder text in right-to-left component orientation. ## 1.5 diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTextFieldUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTextFieldUI.java index 923458a0..5a02d059 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTextFieldUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTextFieldUI.java @@ -237,12 +237,13 @@ public class FlatTextFieldUI // compute placeholder location Rectangle r = getVisibleEditorRect(); FontMetrics fm = c.getFontMetrics( c.getFont() ); + String clippedPlaceholder = JavaCompatibility.getClippedString( c, fm, (String) placeholder, r.width ); + int x = r.x + (c.getComponentOrientation().isLeftToRight() ? 0 : r.width - fm.stringWidth( clippedPlaceholder )); int y = r.y + fm.getAscent() + ((r.height - fm.getHeight()) / 2); // paint placeholder g.setColor( placeholderForeground ); - String clippedPlaceholder = JavaCompatibility.getClippedString( c, fm, (String) placeholder, r.width ); - FlatUIUtils.drawString( c, g, clippedPlaceholder, r.x, y ); + FlatUIUtils.drawString( c, g, clippedPlaceholder, x, y ); } @Override