diff --git a/CHANGELOG.md b/CHANGELOG.md index 54d02b89..18aad455 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ FlatLaf Change Log check whether the current look and feel is FlatLaf. - Fixed selection background of checkbox in table cell. - Fixed jittery submenu rendering on Mac. (issue #10) +- Button: Make button square if button text is "..." or a single character. - ComboBox: Fixed issues with NetBeans `org.openide.awt.ColorComboBox` component. - Hex color values in `.properties` files now must start with a `#` character. diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatButtonUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatButtonUI.java index 72a2c014..87d5c9e7 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatButtonUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatButtonUI.java @@ -163,10 +163,13 @@ public class FlatButtonUI } static boolean isIconOnlyButton( Component c ) { - String text; - return c instanceof JButton && - ((JButton)c).getIcon() != null && - ((text = ((JButton)c).getText()) == null || text.isEmpty()); + if( !(c instanceof JButton) ) + return false; + + Icon icon = ((JButton)c).getIcon(); + String text = ((JButton)c).getText(); + return (icon != null && (text == null || text.isEmpty())) || + (icon == null && text != null && ("...".equals( text ) || text.length() == 1)); } static boolean isHelpButton( Component c ) { @@ -295,8 +298,11 @@ public class FlatButtonUI Dimension prefSize = super.getPreferredSize( c ); - // apply minimum width, if not in toolbar and not a icon-only button - if( !isToolBarButton( c ) && !isIconOnlyButton( c ) ) + // make button square if it is a icon-only button + // or apply minimum width, if not in toolbar and not a icon-only button + if( isIconOnlyButton( c ) ) + prefSize.width = Math.max( prefSize.width, prefSize.height ); + else if( !isToolBarButton( c ) ) prefSize.width = Math.max( prefSize.width, scale( minimumWidth + (focusWidth * 2) ) ); return prefSize; diff --git a/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatComponentsTest.java b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatComponentsTest.java index 1b474e42..7f048d41 100644 --- a/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatComponentsTest.java +++ b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatComponentsTest.java @@ -58,6 +58,9 @@ public class FlatComponentsTest JButton button3 = new JButton(); JButton button12 = new JButton(); JButton button13 = new JButton(); + JButton button14 = new JButton(); + JButton button15 = new JButton(); + JButton button16 = new JButton(); JLabel toggleButtonLabel = new JLabel(); JToggleButton toggleButton1 = new JToggleButton(); JToggleButton toggleButton2 = new JToggleButton(); @@ -263,6 +266,18 @@ public class FlatComponentsTest button13.setIcon(UIManager.getIcon("Tree.closedIcon")); add(button13, "cell 5 1"); + //---- button14 ---- + button14.setText("..."); + add(button14, "cell 5 1"); + + //---- button15 ---- + button15.setText("\u2026"); + add(button15, "cell 5 1"); + + //---- button16 ---- + button16.setText("#"); + add(button16, "cell 5 1"); + //---- toggleButtonLabel ---- toggleButtonLabel.setText("JToggleButton:"); add(toggleButtonLabel, "cell 0 2"); diff --git a/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatComponentsTest.jfd b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatComponentsTest.jfd index 9b653384..22af28a8 100644 --- a/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatComponentsTest.jfd +++ b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatComponentsTest.jfd @@ -85,6 +85,24 @@ new FormModel { }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { "value": "cell 5 1" } ) + add( new FormComponent( "javax.swing.JButton" ) { + name: "button14" + "text": "..." + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 5 1" + } ) + add( new FormComponent( "javax.swing.JButton" ) { + name: "button15" + "text": "…" + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 5 1" + } ) + add( new FormComponent( "javax.swing.JButton" ) { + name: "button16" + "text": "#" + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 5 1" + } ) add( new FormComponent( "javax.swing.JLabel" ) { name: "toggleButtonLabel" "text": "JToggleButton:"