diff --git a/CHANGELOG.md b/CHANGELOG.md index 9aef4ab8..e297c428 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ FlatLaf Change Log ================== +## Unreleased + +- Made some fixes for right-to-left support in ComboBox, Slider and ToolTip. + (issue #18) + + ## 0.15 - ToolTip: Improved styling of dark tooltips (darker background, no border). diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatComboBoxUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatComboBoxUI.java index 564ba8e5..eb5227fd 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatComboBoxUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatComboBoxUI.java @@ -19,6 +19,7 @@ package com.formdev.flatlaf.ui; import static com.formdev.flatlaf.util.UIScale.scale; import java.awt.Color; import java.awt.Component; +import java.awt.ComponentOrientation; import java.awt.Container; import java.awt.Dimension; import java.awt.Graphics; @@ -213,6 +214,9 @@ public class FlatComboBoxUI { // fix editor component colors updateEditorColors(); + } else if( editor != null && source == comboBox && propertyName == "componentOrientation" ) { + ComponentOrientation o = (ComponentOrientation) e.getNewValue(); + editor.applyComponentOrientation( o ); } } }; @@ -235,6 +239,8 @@ public class FlatComboBoxUI if( editor instanceof JTextComponent ) ((JTextComponent)editor).setBorder( BorderFactory.createEmptyBorder() ); + editor.applyComponentOrientation( comboBox.getComponentOrientation() ); + updateEditorColors(); } @@ -315,6 +321,7 @@ public class FlatComboBoxUI CellPaddingBorder.uninstall( renderer ); Component c = renderer.getListCellRendererComponent( listBox, comboBox.getSelectedItem(), -1, false, false ); c.setFont( comboBox.getFont() ); + c.applyComponentOrientation( comboBox.getComponentOrientation() ); CellPaddingBorder.uninstall( c ); boolean enabled = comboBox.isEnabled(); @@ -373,6 +380,15 @@ public class FlatComboBoxUI FlatComboPopup( JComboBox combo ) { super( combo ); + + // BasicComboPopup listens to JComboBox.componentOrientation and updates + // the component orientation of the list, scroller and popup, but when + // switching the LaF and a new combo popup is created, the component + // orientation is not applied. + ComponentOrientation o = comboBox.getComponentOrientation(); + list.setComponentOrientation( o ); + scroller.setComponentOrientation( o ); + setComponentOrientation( o ); } @Override @@ -386,7 +402,13 @@ public class FlatComboBoxUI comboBox.setPrototypeDisplayValue( prototype ); // make popup wider if necessary - pw = Math.max( pw, displaySize.width ); + if( displaySize.width > pw ) { + int diff = displaySize.width - pw; + pw = displaySize.width; + + if( !comboBox.getComponentOrientation().isLeftToRight() ) + px -= diff; + } return super.computePopupBounds( px, py, pw, ph ); } @@ -433,6 +455,7 @@ public class FlatComboBoxUI CellPaddingBorder.uninstall( renderer ); Component c = renderer.getListCellRendererComponent( list, value, index, isSelected, cellHasFocus ); + c.applyComponentOrientation( comboBox.getComponentOrientation() ); if( c instanceof JComponent ) { if( paddingBorder == null ) diff --git a/flatlaf-core/src/test/java/com/formdev/flatlaf/FlatComponentsTest.java b/flatlaf-core/src/test/java/com/formdev/flatlaf/FlatComponentsTest.java index 9f6bdaed..6c1d6a80 100644 --- a/flatlaf-core/src/test/java/com/formdev/flatlaf/FlatComponentsTest.java +++ b/flatlaf-core/src/test/java/com/formdev/flatlaf/FlatComponentsTest.java @@ -243,6 +243,7 @@ public class FlatComponentsTest //---- button5 ---- button5.setText("default"); button5.setDisplayedMnemonicIndex(0); + button5.setToolTipText("Tool tip with\nmultiple\nlines."); add(button5, "cell 3 1"); //---- button3 ---- @@ -346,7 +347,15 @@ public class FlatComponentsTest "editable", "a", "bb", - "ccc" + "ccc", + "dd", + "e", + "ff", + "ggg", + "hh", + "i", + "jj", + "kkk" })); add(comboBox1, "cell 1 5,growx"); @@ -366,7 +375,15 @@ public class FlatComponentsTest "not editable", "a", "bb", - "ccc" + "ccc", + "dd", + "e", + "ff", + "ggg", + "hh", + "i", + "jj", + "kkk" })); add(comboBox3, "cell 3 5,growx"); diff --git a/flatlaf-core/src/test/java/com/formdev/flatlaf/FlatComponentsTest.jfd b/flatlaf-core/src/test/java/com/formdev/flatlaf/FlatComponentsTest.jfd index 6803cc65..c4f47980 100644 --- a/flatlaf-core/src/test/java/com/formdev/flatlaf/FlatComponentsTest.jfd +++ b/flatlaf-core/src/test/java/com/formdev/flatlaf/FlatComponentsTest.jfd @@ -60,6 +60,7 @@ new FormModel { name: "button5" "text": "default" "displayedMnemonicIndex": 0 + "toolTipText": "Tool tip with\nmultiple\nlines." }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { "value": "cell 3 1" } ) @@ -205,6 +206,14 @@ new FormModel { addElement( "a" ) addElement( "bb" ) addElement( "ccc" ) + addElement( "dd" ) + addElement( "e" ) + addElement( "ff" ) + addElement( "ggg" ) + addElement( "hh" ) + addElement( "i" ) + addElement( "jj" ) + addElement( "kkk" ) } }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { "value": "cell 1 5,growx" @@ -231,6 +240,14 @@ new FormModel { addElement( "a" ) addElement( "bb" ) addElement( "ccc" ) + addElement( "dd" ) + addElement( "e" ) + addElement( "ff" ) + addElement( "ggg" ) + addElement( "hh" ) + addElement( "i" ) + addElement( "jj" ) + addElement( "kkk" ) } }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { "value": "cell 3 5,growx" diff --git a/flatlaf-core/src/test/java/com/formdev/flatlaf/FlatInspector.java b/flatlaf-core/src/test/java/com/formdev/flatlaf/FlatInspector.java index 309915e0..ecb91ca6 100644 --- a/flatlaf-core/src/test/java/com/formdev/flatlaf/FlatInspector.java +++ b/flatlaf-core/src/test/java/com/formdev/flatlaf/FlatInspector.java @@ -239,6 +239,7 @@ public class FlatInspector text += "Enabled: " + c.isEnabled() + '\n'; text += "Opaque: " + c.isOpaque() + '\n'; text += "Focusable: " + c.isFocusable() + '\n'; + text += "Left-to-right: " + c.getComponentOrientation().isLeftToRight() + '\n'; text += "Parent: " + c.getParent().getClass().getName(); return text; diff --git a/flatlaf-core/src/test/java/com/formdev/flatlaf/FlatTestFrame.java b/flatlaf-core/src/test/java/com/formdev/flatlaf/FlatTestFrame.java index 4b3889d9..0342da44 100644 --- a/flatlaf-core/src/test/java/com/formdev/flatlaf/FlatTestFrame.java +++ b/flatlaf-core/src/test/java/com/formdev/flatlaf/FlatTestFrame.java @@ -47,6 +47,8 @@ public class FlatTestFrame private JComponent content; private FlatInspector inspector; + public boolean useApplyComponentOrientation; + public static FlatTestFrame create( String[] args, String title ) { Preferences prefs = Preferences.userRoot().node( PREFS_ROOT_PATH ); @@ -307,9 +309,17 @@ public class FlatTestFrame } private void rightToLeftChanged() { - contentPanel.applyComponentOrientation( rightToLeftCheckBox.isSelected() + ComponentOrientation orientation = rightToLeftCheckBox.isSelected() ? ComponentOrientation.RIGHT_TO_LEFT - : ComponentOrientation.LEFT_TO_RIGHT ); + : ComponentOrientation.LEFT_TO_RIGHT; + + if( useApplyComponentOrientation ) + content.applyComponentOrientation( orientation ); + else { + updateComponentsRecur( content, (c, type) -> { + c.setComponentOrientation( orientation ); + } ); + } contentPanel.revalidate(); contentPanel.repaint(); } diff --git a/flatlaf-swingx/src/test/java/com/formdev/flatlaf/swingx/FlatSwingXTest.java b/flatlaf-swingx/src/test/java/com/formdev/flatlaf/swingx/FlatSwingXTest.java index 472fc2b7..3c507b10 100644 --- a/flatlaf-swingx/src/test/java/com/formdev/flatlaf/swingx/FlatSwingXTest.java +++ b/flatlaf-swingx/src/test/java/com/formdev/flatlaf/swingx/FlatSwingXTest.java @@ -32,6 +32,7 @@ public class FlatSwingXTest { public static void main( String[] args ) { FlatTestFrame frame = FlatTestFrame.create( args, "FlatSwingXTest" ); + frame.useApplyComponentOrientation = true; frame.showFrame( new FlatSwingXTest() ); }