From 92c110548ac1aae66c82e3bba34cd9becc7347c8 Mon Sep 17 00:00:00 2001 From: Karl Tauber Date: Fri, 30 Sep 2022 12:30:46 +0200 Subject: [PATCH] ComboBox and Spinner: no longer use preferred height for arrow button width, because preferred height may be zero, which would hide arrow button (see https://github.com/scijava/scijava-ui-swing/issues/77#issuecomment-1261452712) - arrow button width depends on combobox/spinner height - default/max button width is height of a raw combobox/spinner (without insets) - min button width is 3/4 of default button width --- CHANGELOG.md | 8 ++++++++ .../main/java/com/formdev/flatlaf/ui/FlatComboBoxUI.java | 7 +++++-- .../main/java/com/formdev/flatlaf/ui/FlatSpinnerUI.java | 5 +++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e58d802..bb725905 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,14 @@ FlatLaf Change Log ================== +## 3.0-SNAPSHOT + +#### Fixed bugs + +- ComboBox and Spinner: Fixed missing arrow buttons if preferred height is zero. + Minimum width of arrow buttons is 3/4 of default width. + + ## 2.5 #### New features and improvements 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 155e9523..fc634119 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 @@ -308,11 +308,14 @@ public class FlatComboBoxUI // limit button width to height of a raw combobox (without insets) FontMetrics fm = comboBox.getFontMetrics( comboBox.getFont() ); int maxButtonWidth = fm.getHeight() + scale( padding.top ) + scale( padding.bottom ); + int minButtonWidth = (maxButtonWidth * 3) / 4; + // make button square (except if width is limited) Insets insets = getInsets(); - int buttonWidth = Math.min( parent.getPreferredSize().height - insets.top - insets.bottom, maxButtonWidth ); + int buttonWidth = Math.min( Math.max( parent.getHeight() - insets.top - insets.bottom, minButtonWidth ), maxButtonWidth ); + if( buttonWidth != arrowButton.getWidth() ) { - // set width of arrow button to preferred height of combobox + // set width of arrow button int xOffset = comboBox.getComponentOrientation().isLeftToRight() ? arrowButton.getWidth() - buttonWidth : 0; diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatSpinnerUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatSpinnerUI.java index d2b44fa9..1b26b3b0 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatSpinnerUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatSpinnerUI.java @@ -483,9 +483,10 @@ public class FlatSpinnerUI // limit buttons width to height of a raw spinner (without insets) FontMetrics fm = spinner.getFontMetrics( spinner.getFont() ); int maxButtonWidth = fm.getHeight() + scale( padding.top ) + scale( padding.bottom ); + int minButtonWidth = (maxButtonWidth * 3) / 4; - // make button area square (if spinner has preferred height) - int buttonsWidth = Math.min( parent.getPreferredSize().height - insets.top - insets.bottom, maxButtonWidth ); + // make button area square (except if width is limited) + int buttonsWidth = Math.min( Math.max( buttonsRect.height, minButtonWidth ), maxButtonWidth ); buttonsRect.width = buttonsWidth; if( parent.getComponentOrientation().isLeftToRight() ) {