mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-11 22:47:13 -06:00
ComboBox: right-to-left fixes (#18)
This commit is contained in:
@@ -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).
|
||||
|
||||
@@ -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 )
|
||||
|
||||
@@ -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");
|
||||
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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() );
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user