diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e3816e9..0b055641 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ FlatLaf Change Log - ScrollBar: Made styling more flexible by supporting insets and arc for track and thumb. (issue #103) +- ComboBox: Minimum width is now 72 pixels (was ~50 for non-editable and ~130 + for editable comboboxes). - ComboBox: Support custom borders in combobox editors. (issue #102) - Ubuntu Linux: Fixed poorly rendered font. (issue #105) diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatClientProperties.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatClientProperties.java index cbc1566c..ae53d724 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatClientProperties.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatClientProperties.java @@ -99,7 +99,8 @@ public interface FlatClientProperties /** * Specifies minimum width of a component. *
- * Component {@link javax.swing.JButton}, {@link javax.swing.JToggleButton} and {@link javax.swing.text.JTextComponent}
+ * Component {@link javax.swing.JButton}, {@link javax.swing.JToggleButton},
+ * {@link javax.swing.JComboBox}, {@link javax.swing.JSpinner} and {@link javax.swing.text.JTextComponent}
* Value type {@link java.lang.Integer}
*/
String MINIMUM_WIDTH = "JComponent.minimumWidth";
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 d8adc016..e41bfb21 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
@@ -78,6 +78,8 @@ import com.formdev.flatlaf.util.UIScale;
*
*
*
+ * @uiDefault ComboBox.minimumWidth int
+ * @uiDefault ComboBox.editorColumns int
* @uiDefault Component.arrowType String triangle (default) or chevron
* @uiDefault Component.isIntelliJTheme boolean
* @uiDefault Component.borderColor Color
@@ -96,6 +98,8 @@ import com.formdev.flatlaf.util.UIScale;
public class FlatComboBoxUI
extends BasicComboBoxUI
{
+ protected int minimumWidth;
+ protected int editorColumns;
protected String arrowType;
protected boolean isIntelliJTheme;
protected Color borderColor;
@@ -148,6 +152,8 @@ public class FlatComboBoxUI
LookAndFeel.installProperty( comboBox, "opaque", false );
+ minimumWidth = UIManager.getInt( "ComboBox.minimumWidth" );
+ editorColumns = UIManager.getInt( "ComboBox.editorColumns" );
arrowType = UIManager.getString( "Component.arrowType" );
isIntelliJTheme = UIManager.getBoolean( "Component.isIntelliJTheme" );
borderColor = UIManager.getColor( "Component.borderColor" );
@@ -247,6 +253,8 @@ public class FlatComboBoxUI
editor.repaint();
else if( FlatClientProperties.COMPONENT_ROUND_RECT.equals( propertyName ) )
comboBox.repaint();
+ else if( FlatClientProperties.MINIMUM_WIDTH.equals( propertyName ) )
+ comboBox.revalidate();
}
};
}
@@ -263,6 +271,7 @@ public class FlatComboBoxUI
Component editor = comboBoxEditor.getEditorComponent();
if( editor instanceof JTextField ) {
JTextField textField = (JTextField) editor;
+ textField.setColumns( editorColumns );
// assign a non-null and non-javax.swing.plaf.UIResource border to the text field,
// otherwise it is replaced with default text field border when switching LaF
@@ -411,6 +420,13 @@ public class FlatComboBoxUI
return isIntelliJTheme ? FlatUIUtils.getParentBackground( c ) : disabledBackground;
}
+ @Override
+ public Dimension getMinimumSize( JComponent c ) {
+ Dimension minimumSize = super.getMinimumSize( c );
+ minimumSize.width = Math.max( minimumSize.width, scale( FlatUIUtils.minimumWidth( c, minimumWidth ) ) );
+ return minimumSize;
+ }
+
@Override
protected Dimension getDefaultSize() {
@SuppressWarnings( "unchecked" )
@@ -431,6 +447,18 @@ public class FlatComboBoxUI
Dimension displaySize = super.getDisplaySize();
+ // recalculate width without hardcoded 100 under special conditions
+ if( displaySize.width == 100 + padding.left + padding.right &&
+ comboBox.isEditable() &&
+ comboBox.getItemCount() == 0 &&
+ comboBox.getPrototypeDisplayValue() == null )
+ {
+ int width = getDefaultSize().width;
+ width = Math.max( width, editor.getPreferredSize().width );
+ width += padding.left + padding.right;
+ displaySize = new Dimension( width, displaySize.height );
+ }
+
uninstallCellPaddingBorder( renderer );
return displaySize;
}
diff --git a/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLaf.properties b/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLaf.properties
index 1354f284..d5c6dcb0 100644
--- a/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLaf.properties
+++ b/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLaf.properties
@@ -178,6 +178,8 @@ ColorChooser.swatchesDefaultRecentColor=$control
ComboBox.border=com.formdev.flatlaf.ui.FlatRoundBorder
ComboBox.padding=2,6,2,6
+ComboBox.minimumWidth=72
+ComboBox.editorColumns=0
[mac]ComboBox.showPopupOnNavigation=true
diff --git a/flatlaf-testing/src/main/resources/com/formdev/flatlaf/testing/uidefaults/FlatDarkLaf_1.8.0_202.txt b/flatlaf-testing/src/main/resources/com/formdev/flatlaf/testing/uidefaults/FlatDarkLaf_1.8.0_202.txt
index 47fbe940..cb6711f4 100644
--- a/flatlaf-testing/src/main/resources/com/formdev/flatlaf/testing/uidefaults/FlatDarkLaf_1.8.0_202.txt
+++ b/flatlaf-testing/src/main/resources/com/formdev/flatlaf/testing/uidefaults/FlatDarkLaf_1.8.0_202.txt
@@ -185,9 +185,11 @@ ComboBox.buttonHoverArrowColor #bbbbbb javax.swing.plaf.ColorUIResource [UI]
ComboBox.buttonShadow #646464 javax.swing.plaf.ColorUIResource [UI]
ComboBox.disabledBackground #3c3f41 javax.swing.plaf.ColorUIResource [UI]
ComboBox.disabledForeground #777777 javax.swing.plaf.ColorUIResource [UI]
+ComboBox.editorColumns 0
ComboBox.font [active] $defaultFont [UI]
ComboBox.foreground #bbbbbb javax.swing.plaf.ColorUIResource [UI]
ComboBox.isEnterSelectablePopup false
+ComboBox.minimumWidth 72
ComboBox.noActionOnKeyNavigation false
ComboBox.padding 2,6,2,6 javax.swing.plaf.InsetsUIResource [UI]
ComboBox.selectionBackground #4b6eaf javax.swing.plaf.ColorUIResource [UI]
diff --git a/flatlaf-testing/src/main/resources/com/formdev/flatlaf/testing/uidefaults/FlatLightLaf_1.8.0_202.txt b/flatlaf-testing/src/main/resources/com/formdev/flatlaf/testing/uidefaults/FlatLightLaf_1.8.0_202.txt
index 12642abe..f113f6fb 100644
--- a/flatlaf-testing/src/main/resources/com/formdev/flatlaf/testing/uidefaults/FlatLightLaf_1.8.0_202.txt
+++ b/flatlaf-testing/src/main/resources/com/formdev/flatlaf/testing/uidefaults/FlatLightLaf_1.8.0_202.txt
@@ -186,9 +186,11 @@ ComboBox.buttonHoverArrowColor #999999 javax.swing.plaf.ColorUIResource [UI]
ComboBox.buttonShadow #c4c4c4 javax.swing.plaf.ColorUIResource [UI]
ComboBox.disabledBackground #f2f2f2 javax.swing.plaf.ColorUIResource [UI]
ComboBox.disabledForeground #8c8c8c javax.swing.plaf.ColorUIResource [UI]
+ComboBox.editorColumns 0
ComboBox.font [active] $defaultFont [UI]
ComboBox.foreground #000000 javax.swing.plaf.ColorUIResource [UI]
ComboBox.isEnterSelectablePopup false
+ComboBox.minimumWidth 72
ComboBox.noActionOnKeyNavigation false
ComboBox.padding 2,6,2,6 javax.swing.plaf.InsetsUIResource [UI]
ComboBox.selectionBackground #2675bf javax.swing.plaf.ColorUIResource [UI]