diff --git a/CHANGELOG.md b/CHANGELOG.md index 188d8958..0dca90d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ FlatLaf Change Log - TableHeader: Paint column borders if renderer has changed, but delegates to the system default renderer (e.g. done in NetBeans). - Label and ToolTip: Fixed font sizes for HTML headings. +- Button and ToggleButton: Support square button style (set client property + `JButton.buttonType` to `square`). ## 0.23.1 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 10aebe50..3d0bc85d 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatClientProperties.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatClientProperties.java @@ -27,14 +27,25 @@ public interface FlatClientProperties /** * Specifies type of a button. *
- * Component {@link javax.swing.JButton}
+ * Components {@link javax.swing.JButton} and {@link javax.swing.JToggleButton}
* Value type {@link java.lang.String}
- * Allowed Values {@link BUTTON_TYPE_HELP}
+ * Allowed Values {@link #BUTTON_TYPE_SQUARE} and {@link #BUTTON_TYPE_HELP}
*/
String BUTTON_TYPE = "JButton.buttonType";
+ /**
+ * Paint the button with square edges.
+ *
+ * Components {@link javax.swing.JButton} and {@link javax.swing.JToggleButton} + * + * @see #BUTTON_TYPE + */ + String BUTTON_TYPE_SQUARE = "square"; + /** * Paint a help button (circle with question mark). + *
+ * Components {@link javax.swing.JButton} * * @see #BUTTON_TYPE */ @@ -45,7 +56,7 @@ public interface FlatClientProperties *
* Component {@link javax.swing.JCheckBox}
* Value type {@link java.lang.String}
- * Allowed Values {@link SELECTED_STATE_INDETERMINATE}
+ * Allowed Values {@link #SELECTED_STATE_INDETERMINATE}
*/
String SELECTED_STATE = "JButton.selectedState";
diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatBorder.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatBorder.java
index 6d489d6e..a88418e8 100644
--- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatBorder.java
+++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatBorder.java
@@ -75,7 +75,7 @@ public class FlatBorder
boolean isCellEditor = isTableCellEditor( c );
float focusWidth = isCellEditor ? 0 : getFocusWidth();
float borderWidth = getBorderWidth( c );
- float arc = isCellEditor ? 0 : getArc();
+ float arc = isCellEditor ? 0 : getArc( c );
if( isFocused( c ) ) {
g2.setColor( getFocusColor( c ) );
@@ -173,7 +173,7 @@ public class FlatBorder
return getLineWidth();
}
- protected float getArc() {
+ protected float getArc( Component c ) {
return 0;
}
}
diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatButtonBorder.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatButtonBorder.java
index 145565ef..a0341619 100644
--- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatButtonBorder.java
+++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatButtonBorder.java
@@ -110,7 +110,7 @@ public class FlatButtonBorder
}
@Override
- protected float getArc() {
- return scale( (float) arc );
+ protected float getArc( Component c ) {
+ return FlatButtonUI.isSquareButton( c ) ? 0 : scale( (float) arc );
}
}
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 922c6663..9eadebee 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
@@ -209,6 +209,10 @@ public class FlatButtonUI
(icon == null && text != null && ("...".equals( text ) || text.length() == 1));
}
+ static boolean isSquareButton( Component c ) {
+ return c instanceof AbstractButton && clientPropertyEquals( (AbstractButton) c, BUTTON_TYPE, BUTTON_TYPE_SQUARE );
+ }
+
static boolean isHelpButton( Component c ) {
return c instanceof JButton && clientPropertyEquals( (JButton) c, BUTTON_TYPE, BUTTON_TYPE_HELP );
}
@@ -237,7 +241,8 @@ public class FlatButtonUI
Border border = c.getBorder();
float focusWidth = (border instanceof FlatBorder) ? scale( (float) this.focusWidth ) : 0;
- float arc = (border instanceof FlatButtonBorder || isToolBarButton( c )) ? scale( (float) this.arc ) : 0;
+ float arc = ((border instanceof FlatButtonBorder && !isSquareButton( c )) || isToolBarButton( c ))
+ ? scale( (float) this.arc ) : 0;
boolean def = isDefaultButton( c );
// paint shadow
diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatRoundBorder.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatRoundBorder.java
index 66960f75..0eced1f2 100644
--- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatRoundBorder.java
+++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatRoundBorder.java
@@ -17,6 +17,7 @@
package com.formdev.flatlaf.ui;
import static com.formdev.flatlaf.util.UIScale.scale;
+import java.awt.Component;
import javax.swing.UIManager;
/**
@@ -32,7 +33,7 @@ public class FlatRoundBorder
protected final int arc = UIManager.getInt( "Component.arc" );
@Override
- protected float getArc() {
+ protected float getArc( Component c ) {
return scale( (float) arc );
}
}
diff --git a/flatlaf-demo/src/main/java/com/formdev/flatlaf/demo/BasicComponentsPanel.java b/flatlaf-demo/src/main/java/com/formdev/flatlaf/demo/BasicComponentsPanel.java
index 7ed32f2b..b7ca8714 100644
--- a/flatlaf-demo/src/main/java/com/formdev/flatlaf/demo/BasicComponentsPanel.java
+++ b/flatlaf-demo/src/main/java/com/formdev/flatlaf/demo/BasicComponentsPanel.java
@@ -37,6 +37,8 @@ class BasicComponentsPanel
JLabel buttonLabel = new JLabel();
JButton button1 = new JButton();
JButton button2 = new JButton();
+ JButton button5 = new JButton();
+ JButton button6 = new JButton();
JButton button3 = new JButton();
JButton button4 = new JButton();
JButton button13 = new JButton();
@@ -166,10 +168,21 @@ class BasicComponentsPanel
button2.setEnabled(false);
add(button2, "cell 2 1");
+ //---- button5 ----
+ button5.setText("square");
+ button5.putClientProperty("JButton.buttonType", "square");
+ add(button5, "cell 3 1");
+
+ //---- button6 ----
+ button6.setText("square");
+ button6.setEnabled(false);
+ button6.putClientProperty("JButton.buttonType", "square");
+ add(button6, "cell 4 1");
+
//---- button3 ----
button3.setText("Help");
button3.putClientProperty("JButton.buttonType", "help");
- add(button3, "cell 3 1");
+ add(button3, "cell 4 1");
//---- button4 ----
button4.setText("Help");
diff --git a/flatlaf-demo/src/main/java/com/formdev/flatlaf/demo/BasicComponentsPanel.jfd b/flatlaf-demo/src/main/java/com/formdev/flatlaf/demo/BasicComponentsPanel.jfd
index c778d423..469a8884 100644
--- a/flatlaf-demo/src/main/java/com/formdev/flatlaf/demo/BasicComponentsPanel.jfd
+++ b/flatlaf-demo/src/main/java/com/formdev/flatlaf/demo/BasicComponentsPanel.jfd
@@ -1,4 +1,4 @@
-JFDML JFormDesigner: "7.0.0.0.194" Java: "11.0.2" encoding: "UTF-8"
+JFDML JFormDesigner: "7.0.0.0.194" Java: "13.0.1" encoding: "UTF-8"
new FormModel {
contentType: "form/swing"
@@ -54,12 +54,27 @@ new FormModel {
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 2 1"
} )
+ add( new FormComponent( "javax.swing.JButton" ) {
+ name: "button5"
+ "text": "square"
+ "$client.JButton.buttonType": "square"
+ }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
+ "value": "cell 3 1"
+ } )
+ add( new FormComponent( "javax.swing.JButton" ) {
+ name: "button6"
+ "text": "square"
+ "enabled": false
+ "$client.JButton.buttonType": "square"
+ }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
+ "value": "cell 4 1"
+ } )
add( new FormComponent( "javax.swing.JButton" ) {
name: "button3"
"text": "Help"
"$client.JButton.buttonType": "help"
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
- "value": "cell 3 1"
+ "value": "cell 4 1"
} )
add( new FormComponent( "javax.swing.JButton" ) {
name: "button4"
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 90c710e6..07aa13de 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
@@ -61,7 +61,9 @@ public class FlatComponentsTest
JLabel label2 = new JLabel();
JLabel buttonLabel = new JLabel();
JButton button1 = new JButton();
+ JButton button17 = new JButton();
JButton button2 = new JButton();
+ JButton button18 = new JButton();
FlatComponentsTest.TestDefaultButton button5 = new FlatComponentsTest.TestDefaultButton();
JButton button3 = new JButton();
JButton button12 = new JButton();
@@ -71,7 +73,9 @@ public class FlatComponentsTest
JButton button16 = new JButton();
JLabel toggleButtonLabel = new JLabel();
JToggleButton toggleButton1 = new JToggleButton();
+ JToggleButton toggleButton9 = new JToggleButton();
JToggleButton toggleButton2 = new JToggleButton();
+ JToggleButton toggleButton10 = new JToggleButton();
JToggleButton toggleButton3 = new JToggleButton();
JToggleButton toggleButton4 = new JToggleButton();
JLabel checkBoxLabel = new JLabel();
@@ -249,6 +253,11 @@ public class FlatComponentsTest
button1.setToolTipText("This button is enabled.");
add(button1, "cell 1 1");
+ //---- button17 ----
+ button17.setText("square");
+ button17.putClientProperty("JButton.buttonType", "square");
+ add(button17, "cell 1 1");
+
//---- button2 ----
button2.setText("disabled");
button2.setDisplayedMnemonicIndex(0);
@@ -256,6 +265,12 @@ public class FlatComponentsTest
button2.setToolTipText("This button is disabled.");
add(button2, "cell 2 1");
+ //---- button18 ----
+ button18.setText("square");
+ button18.putClientProperty("JButton.buttonType", "square");
+ button18.setEnabled(false);
+ add(button18, "cell 2 1");
+
//---- button5 ----
button5.setText("default");
button5.setDisplayedMnemonicIndex(0);
@@ -297,11 +312,22 @@ public class FlatComponentsTest
toggleButton1.setText("enabled");
add(toggleButton1, "cell 1 2");
+ //---- toggleButton9 ----
+ toggleButton9.setText("square");
+ toggleButton9.putClientProperty("JButton.buttonType", "square");
+ add(toggleButton9, "cell 1 2");
+
//---- toggleButton2 ----
toggleButton2.setText("disabled");
toggleButton2.setEnabled(false);
add(toggleButton2, "cell 2 2");
+ //---- toggleButton10 ----
+ toggleButton10.setText("square");
+ toggleButton10.putClientProperty("JButton.buttonType", "square");
+ toggleButton10.setEnabled(false);
+ add(toggleButton10, "cell 2 2");
+
//---- toggleButton3 ----
toggleButton3.setText("selected");
toggleButton3.setSelected(true);
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 0ab48b7e..2f32943f 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
@@ -47,6 +47,13 @@ new FormModel {
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 1 1"
} )
+ add( new FormComponent( "javax.swing.JButton" ) {
+ name: "button17"
+ "text": "square"
+ "$client.JButton.buttonType": "square"
+ }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
+ "value": "cell 1 1"
+ } )
add( new FormComponent( "javax.swing.JButton" ) {
name: "button2"
"text": "disabled"
@@ -56,6 +63,14 @@ new FormModel {
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 2 1"
} )
+ add( new FormComponent( "javax.swing.JButton" ) {
+ name: "button18"
+ "text": "square"
+ "$client.JButton.buttonType": "square"
+ "enabled": false
+ }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
+ "value": "cell 2 1"
+ } )
add( new FormComponent( "com.formdev.flatlaf.testing.FlatComponentsTest$TestDefaultButton" ) {
name: "button5"
"text": "default"
@@ -115,6 +130,13 @@ new FormModel {
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 1 2"
} )
+ add( new FormComponent( "javax.swing.JToggleButton" ) {
+ name: "toggleButton9"
+ "text": "square"
+ "$client.JButton.buttonType": "square"
+ }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
+ "value": "cell 1 2"
+ } )
add( new FormComponent( "javax.swing.JToggleButton" ) {
name: "toggleButton2"
"text": "disabled"
@@ -122,6 +144,14 @@ new FormModel {
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 2 2"
} )
+ add( new FormComponent( "javax.swing.JToggleButton" ) {
+ name: "toggleButton10"
+ "text": "square"
+ "$client.JButton.buttonType": "square"
+ "enabled": false
+ }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
+ "value": "cell 2 2"
+ } )
add( new FormComponent( "javax.swing.JToggleButton" ) {
name: "toggleButton3"
"text": "selected"
@@ -935,7 +965,7 @@ new FormModel {
} )
}, new FormLayoutConstraints( null ) {
"location": new java.awt.Point( 0, 0 )
- "size": new java.awt.Dimension( 865, 800 )
+ "size": new java.awt.Dimension( 1005, 800 )
} )
}
}