diff --git a/CHANGELOG.md b/CHANGELOG.md index 6790cd05d..7f8dd0bca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ FlatLaf Change Log #### New features and improvements +- ComboBox: Support rounded selection. (PR #548) - List: Support rounded selection. (PR #547) - Menus: Support rounded selection. (PR #536) - Tree: Support rounded selection. (PR #546) 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 fc6341196..e933030c8 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 @@ -117,6 +117,9 @@ * @uiDefault ComboBox.buttonHoverArrowColor Color * @uiDefault ComboBox.buttonPressedArrowColor Color * @uiDefault ComboBox.popupBackground Color optional + * @uiDefault ComboBox.popupInsets Insets + * @uiDefault ComboBox.selectionInsets Insets + * @uiDefault ComboBox.selectionArc int * * @author Karl Tauber */ @@ -150,6 +153,9 @@ public class FlatComboBoxUI @Styleable protected Color buttonPressedArrowColor; @Styleable protected Color popupBackground; + /** @since 3 */ @Styleable protected Insets popupInsets; + /** @since 3 */ @Styleable protected Insets selectionInsets; + /** @since 3 */ @Styleable protected int selectionArc; private MouseListener hoverListener; protected boolean hover; @@ -253,6 +259,9 @@ protected void installDefaults() { buttonPressedArrowColor = UIManager.getColor( "ComboBox.buttonPressedArrowColor" ); popupBackground = UIManager.getColor( "ComboBox.popupBackground" ); + popupInsets = UIManager.getInsets( "ComboBox.popupInsets" ); + selectionInsets = UIManager.getInsets( "ComboBox.selectionInsets" ); + selectionArc = UIManager.getInt( "ComboBox.selectionArc" ); // set maximumRowCount int maximumRowCount = UIManager.getInt( "ComboBox.maximumRowCount" ); @@ -842,17 +851,12 @@ protected void configurePopup() { // make opaque to avoid that background shines thru border (e.g. at 150% scaling) setOpaque( true ); - // set popup border - // use non-UIResource to avoid that it is overwritten when making - // popup visible (see JPopupMenu.setInvoker()) in theme editor preview + // set popup border + // use non-UIResource to avoid that it is overwritten when making + // popup visible (see JPopupMenu.setInvoker()) in theme editor preview Border border = UIManager.getBorder( "PopupMenu.border" ); if( border != null ) setBorder( FlatUIUtils.nonUIResource( border ) ); - } - - @Override - protected void configureList() { - super.configureList(); list.setCellRenderer( new PopupListCellRenderer() ); updateStyle(); @@ -860,12 +864,21 @@ protected void configureList() { void updateStyle() { if( popupBackground != null ) - list.setBackground( popupBackground ); + list.setBackground( popupBackground ); - // set popup background because it may shine thru when scaled (e.g. at 150%) - // use non-UIResource to avoid that it is overwritten when making - // popup visible (see JPopupMenu.setInvoker()) in theme editor preview - setBackground( FlatUIUtils.nonUIResource( list.getBackground() ) ); + // set popup background because it may shine thru when scaled (e.g. at 150%) + // use non-UIResource to avoid that it is overwritten when making + // popup visible (see JPopupMenu.setInvoker()) in theme editor preview + setBackground( FlatUIUtils.nonUIResource( list.getBackground() ) ); + + scroller.setViewportBorder( (popupInsets != null) ? new FlatEmptyBorder( popupInsets ) : null ); + scroller.setOpaque( false ); + + if( list.getUI() instanceof FlatListUI ) { + FlatListUI ui = (FlatListUI) list.getUI(); + ui.selectionInsets = selectionInsets; + ui.selectionArc = selectionArc; + } } @Override diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatListUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatListUI.java index 3fd228ac8..a564ff3c0 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatListUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatListUI.java @@ -37,6 +37,7 @@ import javax.swing.UIManager; import javax.swing.event.ListSelectionListener; import javax.swing.plaf.ComponentUI; +import javax.swing.plaf.basic.BasicComboBoxRenderer; import javax.swing.plaf.basic.BasicListUI; import com.formdev.flatlaf.FlatClientProperties; import com.formdev.flatlaf.ui.FlatStylingSupport.Styleable; @@ -319,7 +320,8 @@ protected void paintCell( Graphics g, int row, Rectangle rowBounds, ListCellRend // rounded selection or selection insets if( isSelected && !isFileList && // rounded selection is not supported for file list - rendererComponent instanceof DefaultListCellRenderer && + (rendererComponent instanceof DefaultListCellRenderer || + rendererComponent instanceof BasicComboBoxRenderer) && (selectionArc > 0 || (selectionInsets != null && (selectionInsets.top != 0 || selectionInsets.left != 0 || selectionInsets.bottom != 0 || selectionInsets.right != 0))) ) 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 81e3c4ddb..db89b46f5 100644 --- a/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLaf.properties +++ b/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLaf.properties @@ -285,6 +285,10 @@ ComboBox.buttonDisabledArrowColor = @buttonDisabledArrowColor ComboBox.buttonHoverArrowColor = @buttonHoverArrowColor ComboBox.buttonPressedArrowColor = @buttonPressedArrowColor +ComboBox.popupInsets = 0,0,0,0 +ComboBox.selectionInsets = 0,0,0,0 +ComboBox.selectionArc = 0 + #---- Component ---- diff --git a/flatlaf-core/src/test/java/com/formdev/flatlaf/ui/TestFlatStyleableInfo.java b/flatlaf-core/src/test/java/com/formdev/flatlaf/ui/TestFlatStyleableInfo.java index 980914c90..79bbf2c3d 100644 --- a/flatlaf-core/src/test/java/com/formdev/flatlaf/ui/TestFlatStyleableInfo.java +++ b/flatlaf-core/src/test/java/com/formdev/flatlaf/ui/TestFlatStyleableInfo.java @@ -185,7 +185,10 @@ void comboBox() { "buttonHoverArrowColor", Color.class, "buttonPressedArrowColor", Color.class, - "popupBackground", Color.class + "popupBackground", Color.class, + "popupInsets", Insets.class, + "selectionInsets", Insets.class, + "selectionArc", int.class ); // border diff --git a/flatlaf-core/src/test/java/com/formdev/flatlaf/ui/TestFlatStyling.java b/flatlaf-core/src/test/java/com/formdev/flatlaf/ui/TestFlatStyling.java index 031f5d579..a224ad3ce 100644 --- a/flatlaf-core/src/test/java/com/formdev/flatlaf/ui/TestFlatStyling.java +++ b/flatlaf-core/src/test/java/com/formdev/flatlaf/ui/TestFlatStyling.java @@ -316,6 +316,9 @@ void comboBox() { ui.applyStyle( "buttonPressedArrowColor: #fff" ); ui.applyStyle( "popupBackground: #fff" ); + ui.applyStyle( "popupInsets: 1,2,3,4" ); + ui.applyStyle( "selectionInsets: 1,2,3,4" ); + ui.applyStyle( "selectionArc: 8" ); // border flatRoundBorder( style -> ui.applyStyle( style ) ); diff --git a/flatlaf-testing/dumps/uidefaults/FlatDarkLaf_1.8.0.txt b/flatlaf-testing/dumps/uidefaults/FlatDarkLaf_1.8.0.txt index d0b2160b6..25de3fa64 100644 --- a/flatlaf-testing/dumps/uidefaults/FlatDarkLaf_1.8.0.txt +++ b/flatlaf-testing/dumps/uidefaults/FlatDarkLaf_1.8.0.txt @@ -220,8 +220,11 @@ ComboBox.maximumRowCount 15 ComboBox.minimumWidth 72 ComboBox.noActionOnKeyNavigation false ComboBox.padding 2,6,2,6 javax.swing.plaf.InsetsUIResource [UI] +ComboBox.popupInsets 0,0,0,0 javax.swing.plaf.InsetsUIResource [UI] +ComboBox.selectionArc 0 ComboBox.selectionBackground #4b6eaf HSL 219 40 49 javax.swing.plaf.ColorUIResource [UI] ComboBox.selectionForeground #bbbbbb HSL 0 0 73 javax.swing.plaf.ColorUIResource [UI] +ComboBox.selectionInsets 0,0,0,0 javax.swing.plaf.InsetsUIResource [UI] ComboBox.timeFactor 1000 ComboBoxUI com.formdev.flatlaf.ui.FlatComboBoxUI diff --git a/flatlaf-testing/dumps/uidefaults/FlatLightLaf_1.8.0.txt b/flatlaf-testing/dumps/uidefaults/FlatLightLaf_1.8.0.txt index 4c487c06f..56ef95745 100644 --- a/flatlaf-testing/dumps/uidefaults/FlatLightLaf_1.8.0.txt +++ b/flatlaf-testing/dumps/uidefaults/FlatLightLaf_1.8.0.txt @@ -224,8 +224,11 @@ ComboBox.maximumRowCount 15 ComboBox.minimumWidth 72 ComboBox.noActionOnKeyNavigation false ComboBox.padding 2,6,2,6 javax.swing.plaf.InsetsUIResource [UI] +ComboBox.popupInsets 0,0,0,0 javax.swing.plaf.InsetsUIResource [UI] +ComboBox.selectionArc 0 ComboBox.selectionBackground #2675bf HSL 209 67 45 javax.swing.plaf.ColorUIResource [UI] ComboBox.selectionForeground #ffffff HSL 0 0 100 javax.swing.plaf.ColorUIResource [UI] +ComboBox.selectionInsets 0,0,0,0 javax.swing.plaf.InsetsUIResource [UI] ComboBox.timeFactor 1000 ComboBoxUI com.formdev.flatlaf.ui.FlatComboBoxUI diff --git a/flatlaf-testing/dumps/uidefaults/FlatTestLaf_1.8.0.txt b/flatlaf-testing/dumps/uidefaults/FlatTestLaf_1.8.0.txt index 85e6ab17d..6392d02c3 100644 --- a/flatlaf-testing/dumps/uidefaults/FlatTestLaf_1.8.0.txt +++ b/flatlaf-testing/dumps/uidefaults/FlatTestLaf_1.8.0.txt @@ -245,8 +245,11 @@ ComboBox.minimumWidth 72 ComboBox.noActionOnKeyNavigation false ComboBox.padding 2,6,2,6 javax.swing.plaf.InsetsUIResource [UI] ComboBox.popupBackground #ffffcc HSL 60 100 90 javax.swing.plaf.ColorUIResource [UI] +ComboBox.popupInsets 0,0,0,0 javax.swing.plaf.InsetsUIResource [UI] +ComboBox.selectionArc 0 ComboBox.selectionBackground #00aa00 HSL 120 100 33 javax.swing.plaf.ColorUIResource [UI] ComboBox.selectionForeground #ffff00 HSL 60 100 50 javax.swing.plaf.ColorUIResource [UI] +ComboBox.selectionInsets 0,0,0,0 javax.swing.plaf.InsetsUIResource [UI] ComboBox.timeFactor 1000 ComboBoxUI com.formdev.flatlaf.ui.FlatComboBoxUI diff --git a/flatlaf-theme-editor/src/main/resources/com/formdev/flatlaf/themeeditor/FlatLafUIKeys.txt b/flatlaf-theme-editor/src/main/resources/com/formdev/flatlaf/themeeditor/FlatLafUIKeys.txt index 5a053a6db..b64efc4a0 100644 --- a/flatlaf-theme-editor/src/main/resources/com/formdev/flatlaf/themeeditor/FlatLafUIKeys.txt +++ b/flatlaf-theme-editor/src/main/resources/com/formdev/flatlaf/themeeditor/FlatLafUIKeys.txt @@ -208,8 +208,11 @@ ComboBox.minimumWidth ComboBox.noActionOnKeyNavigation ComboBox.padding ComboBox.popupBackground +ComboBox.popupInsets +ComboBox.selectionArc ComboBox.selectionBackground ComboBox.selectionForeground +ComboBox.selectionInsets ComboBox.timeFactor ComboBoxUI Component.accentColor