mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2025-12-06 14:00:55 +03:00
Button and ToggleButton: support square button style
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -27,14 +27,25 @@ public interface FlatClientProperties
|
||||
/**
|
||||
* Specifies type of a button.
|
||||
* <p>
|
||||
* <strong>Component</strong> {@link javax.swing.JButton}<br>
|
||||
* <strong>Components</strong> {@link javax.swing.JButton} and {@link javax.swing.JToggleButton}<br>
|
||||
* <strong>Value type</strong> {@link java.lang.String}<br>
|
||||
* <strong>Allowed Values</strong> {@link BUTTON_TYPE_HELP}
|
||||
* <strong>Allowed Values</strong> {@link #BUTTON_TYPE_SQUARE} and {@link #BUTTON_TYPE_HELP}
|
||||
*/
|
||||
String BUTTON_TYPE = "JButton.buttonType";
|
||||
|
||||
/**
|
||||
* Paint the button with square edges.
|
||||
* <p>
|
||||
* <strong>Components</strong> {@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).
|
||||
* <p>
|
||||
* <strong>Components</strong> {@link javax.swing.JButton}
|
||||
*
|
||||
* @see #BUTTON_TYPE
|
||||
*/
|
||||
@@ -45,7 +56,7 @@ public interface FlatClientProperties
|
||||
* <p>
|
||||
* <strong>Component</strong> {@link javax.swing.JCheckBox}<br>
|
||||
* <strong>Value type</strong> {@link java.lang.String}<br>
|
||||
* <strong>Allowed Values</strong> {@link SELECTED_STATE_INDETERMINATE}
|
||||
* <strong>Allowed Values</strong> {@link #SELECTED_STATE_INDETERMINATE}
|
||||
*/
|
||||
String SELECTED_STATE = "JButton.selectedState";
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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 )
|
||||
} )
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user