Icons: scale checkbox and radiobutton icons when using text styles large, medium, small and mini (issue #1061)

https://www.formdev.com/flatlaf/typography/#text_styles

Theme Editor: added to preview
This commit is contained in:
Karl Tauber
2025-12-03 12:45:00 +01:00
parent 5b0f13110a
commit 070cf9c40d
11 changed files with 351 additions and 9 deletions

View File

@@ -8,6 +8,11 @@ FlatLaf Change Log
- System File Chooser allows using **operating system file dialogs** in Java
Swing applications. (PR #988)
- Zooming API. (PR #1051)
- Icons:
- Support scaling Laf icons (checkbox, radiobutton, etc). (issue #1061)
- Scale checkbox and radiobutton icons when using
[text styles](https://www.formdev.com/flatlaf/typography/#text_styles)
`large`, `medium`, `small` and `mini`.
- TabbedPane: Added icon-only tab mode, which shows tab icons but hides tab
titles. Tab titles are used in "Show Hidden Tabs" popup menu. (set client
property `JTabbedPane.tabWidthMode` to `"iconOnly"`)

View File

@@ -977,6 +977,24 @@ Tree.icon.openColor = @icon
#---- Styles ------------------------------------------------------------------
#---- scale icons ----
@largeScale = 1.125
@mediumScale = 0.875
@smallScale = 0.8125
@miniScale = 0.75
[style]CheckBox.large = icon.scale: @largeScale; iconTextGap: 5
[style]CheckBox.medium = icon.scale: @mediumScale
[style]CheckBox.small = icon.scale: @smallScale; iconTextGap: 3
[style]CheckBox.mini = icon.scale: @miniScale; iconTextGap: 3
[style]RadioButton.large = icon.scale: @largeScale; iconTextGap: 5
[style]RadioButton.medium = icon.scale: @mediumScale
[style]RadioButton.small = icon.scale: @smallScale; iconTextGap: 3
[style]RadioButton.mini = icon.scale: @miniScale; iconTextGap: 3
#---- inTextField ----
# for leading/trailing components in text fields

View File

@@ -1503,6 +1503,22 @@ ViewportUI com.formdev.flatlaf.ui.FlatViewportUI
[style]Button.inTextField focusable: false; toolbar.margin: 1,1,1,1; toolbar.spacingInsets: 1,1,1,1; toolbar.hoverBackground: lighten($TextField.background,5%); toolbar.pressedBackground: lighten($TextField.background,10%); toolbar.selectedBackground: lighten($TextField.background,15%)
#---- [style]CheckBox ----
[style]CheckBox.large icon.scale: @largeScale; iconTextGap: 5
[style]CheckBox.medium icon.scale: @mediumScale
[style]CheckBox.mini icon.scale: @miniScale; iconTextGap: 3
[style]CheckBox.small icon.scale: @smallScale; iconTextGap: 3
#---- [style]RadioButton ----
[style]RadioButton.large icon.scale: @largeScale; iconTextGap: 5
[style]RadioButton.medium icon.scale: @mediumScale
[style]RadioButton.mini icon.scale: @miniScale; iconTextGap: 3
[style]RadioButton.small icon.scale: @smallScale; iconTextGap: 3
#---- [style]ToggleButton ----
[style]ToggleButton.inTextField focusable: false; toolbar.margin: 1,1,1,1; toolbar.spacingInsets: 1,1,1,1; toolbar.hoverBackground: lighten($TextField.background,5%); toolbar.pressedBackground: lighten($TextField.background,10%); toolbar.selectedBackground: lighten($TextField.background,15%)

View File

@@ -1508,6 +1508,22 @@ ViewportUI com.formdev.flatlaf.ui.FlatViewportUI
[style]Button.inTextField focusable: false; toolbar.margin: 1,1,1,1; toolbar.spacingInsets: 1,1,1,1; toolbar.hoverBackground: darken($TextField.background,4%); toolbar.pressedBackground: darken($TextField.background,8%); toolbar.selectedBackground: darken($TextField.background,12%)
#---- [style]CheckBox ----
[style]CheckBox.large icon.scale: @largeScale; iconTextGap: 5
[style]CheckBox.medium icon.scale: @mediumScale
[style]CheckBox.mini icon.scale: @miniScale; iconTextGap: 3
[style]CheckBox.small icon.scale: @smallScale; iconTextGap: 3
#---- [style]RadioButton ----
[style]RadioButton.large icon.scale: @largeScale; iconTextGap: 5
[style]RadioButton.medium icon.scale: @mediumScale
[style]RadioButton.mini icon.scale: @miniScale; iconTextGap: 3
[style]RadioButton.small icon.scale: @smallScale; iconTextGap: 3
#---- [style]ToggleButton ----
[style]ToggleButton.inTextField focusable: false; toolbar.margin: 1,1,1,1; toolbar.spacingInsets: 1,1,1,1; toolbar.hoverBackground: darken($TextField.background,4%); toolbar.pressedBackground: darken($TextField.background,8%); toolbar.selectedBackground: darken($TextField.background,12%)

View File

@@ -1513,6 +1513,22 @@ ViewportUI com.formdev.flatlaf.ui.FlatViewportUI
[style]Button.inTextField focusable: false; toolbar.margin: 1,1,1,1; toolbar.spacingInsets: 1,1,1,1; toolbar.hoverBackground: lighten($TextField.background,5%); toolbar.pressedBackground: lighten($TextField.background,10%); toolbar.selectedBackground: lighten($TextField.background,15%)
#---- [style]CheckBox ----
[style]CheckBox.large icon.scale: @largeScale; iconTextGap: 5
[style]CheckBox.medium icon.scale: @mediumScale
[style]CheckBox.mini icon.scale: @miniScale; iconTextGap: 3
[style]CheckBox.small icon.scale: @smallScale; iconTextGap: 3
#---- [style]RadioButton ----
[style]RadioButton.large icon.scale: @largeScale; iconTextGap: 5
[style]RadioButton.medium icon.scale: @mediumScale
[style]RadioButton.mini icon.scale: @miniScale; iconTextGap: 3
[style]RadioButton.small icon.scale: @smallScale; iconTextGap: 3
#---- [style]ToggleButton ----
[style]ToggleButton.inTextField focusable: false; toolbar.margin: 1,1,1,1; toolbar.spacingInsets: 1,1,1,1; toolbar.hoverBackground: lighten($TextField.background,5%); toolbar.pressedBackground: lighten($TextField.background,10%); toolbar.selectedBackground: lighten($TextField.background,15%)

View File

@@ -1517,6 +1517,22 @@ ViewportUI com.formdev.flatlaf.ui.FlatViewportUI
[style]Button.inTextField focusable: false; toolbar.margin: 1,1,1,1; toolbar.spacingInsets: 1,1,1,1; toolbar.hoverBackground: darken($TextField.background,4%); toolbar.pressedBackground: darken($TextField.background,8%); toolbar.selectedBackground: darken($TextField.background,12%)
#---- [style]CheckBox ----
[style]CheckBox.large icon.scale: @largeScale; iconTextGap: 5
[style]CheckBox.medium icon.scale: @mediumScale
[style]CheckBox.mini icon.scale: @miniScale; iconTextGap: 3
[style]CheckBox.small icon.scale: @smallScale; iconTextGap: 3
#---- [style]RadioButton ----
[style]RadioButton.large icon.scale: @largeScale; iconTextGap: 5
[style]RadioButton.medium icon.scale: @mediumScale
[style]RadioButton.mini icon.scale: @miniScale; iconTextGap: 3
[style]RadioButton.small icon.scale: @smallScale; iconTextGap: 3
#---- [style]ToggleButton ----
[style]ToggleButton.inTextField focusable: false; toolbar.margin: 1,1,1,1; toolbar.spacingInsets: 1,1,1,1; toolbar.hoverBackground: darken($TextField.background,4%); toolbar.pressedBackground: darken($TextField.background,8%); toolbar.selectedBackground: darken($TextField.background,12%)

View File

@@ -1570,6 +1570,22 @@ ViewportUI com.formdev.flatlaf.ui.FlatViewportUI
[style]Button.inTextField focusable: false; toolbar.margin: 1,1,1,1; toolbar.spacingInsets: 1,1,1,1
#---- [style]CheckBox ----
[style]CheckBox.large icon.scale: @largeScale; iconTextGap: 5
[style]CheckBox.medium icon.scale: @mediumScale
[style]CheckBox.mini icon.scale: @miniScale; iconTextGap: 3
[style]CheckBox.small icon.scale: @smallScale; iconTextGap: 3
#---- [style]RadioButton ----
[style]RadioButton.large icon.scale: @largeScale; iconTextGap: 5
[style]RadioButton.medium icon.scale: @mediumScale
[style]RadioButton.mini icon.scale: @miniScale; iconTextGap: 3
[style]RadioButton.small icon.scale: @smallScale; iconTextGap: 3
#---- [style]ToggleButton ----
[style]ToggleButton.inTextField focusable: false; toolbar.margin: 1,1,1,1; toolbar.spacingInsets: 1,1,1,1

View File

@@ -1,4 +1,4 @@
JFDML JFormDesigner: "7.0.5.0.382" Java: "16" encoding: "UTF-8"
JFDML JFormDesigner: "8.3" encoding: "UTF-8"
new FormModel {
contentType: "form/swing"
@@ -146,8 +146,8 @@ new FormModel {
"value": "cell 0 16"
} )
}, new FormLayoutConstraints( null ) {
"location": new java.awt.Point( 5, 0 )
"size": new java.awt.Dimension( 335, 495 )
"location": new java.awt.Point( 0, 0 )
"size": new java.awt.Dimension( 335, 675 )
} )
add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) {
"$layoutConstraints": "insets 0,hidemode 3"
@@ -188,7 +188,7 @@ new FormModel {
"value": "cell 1 0"
} )
}, new FormLayoutConstraints( null ) {
"location": new java.awt.Point( 5, 545 )
"location": new java.awt.Point( 0, 715 )
"size": new java.awt.Dimension( 235, 65 )
} )
}

View File

@@ -206,6 +206,24 @@ class FlatThemePreviewSwitches
JLabel label32 = new JLabel();
FlatThemePreviewSwitches.ZoomRadioButton radioButton1 = new FlatThemePreviewSwitches.ZoomRadioButton();
FlatThemePreviewSwitches.ZoomRadioButton radioButton2 = new FlatThemePreviewSwitches.ZoomRadioButton();
JLabel label39 = new JLabel();
JLabel label5 = new JLabel();
JLabel label6 = new JLabel();
JLabel largeLabel = new JLabel();
JCheckBox largeCheckBox = new JCheckBox();
JRadioButton largeRadioButton = new JRadioButton();
JLabel defaultLabel = new JLabel();
JCheckBox defaultCheckBox = new JCheckBox();
JRadioButton defaultRadioButton = new JRadioButton();
JLabel mediumLabel = new JLabel();
JCheckBox mediumCheckBox = new JCheckBox();
JRadioButton mediumRadioButton = new JRadioButton();
JLabel smallLabel = new JLabel();
JCheckBox smallCheckBox = new JCheckBox();
JRadioButton smallRadioButton = new JRadioButton();
JLabel miniLabel = new JLabel();
JCheckBox miniCheckBox = new JCheckBox();
JRadioButton miniRadioButton = new JRadioButton();
//======== this ========
setLayout(new MigLayout(
@@ -236,6 +254,13 @@ class FlatThemePreviewSwitches
"[]" +
"[]" +
"[]unrel" +
"[]para" +
"[]" +
"[]" +
"[]" +
"[]" +
"[]" +
"[]" +
"[]"));
//======== panel1 ========
@@ -583,6 +608,91 @@ class FlatThemePreviewSwitches
radioButton2.setSelected(true);
add(radioButton2, "cell 2 16");
//---- label39 ----
label39.setText("Sizes");
label39.putClientProperty(FlatClientProperties.STYLE_CLASS, "h3");
add(label39, "cell 0 17 3 1");
//---- label5 ----
label5.setText("JCheckBox");
add(label5, "cell 1 18 3 1,alignx left,growx 0");
//---- label6 ----
label6.setText("JRadioButton");
add(label6, "cell 4 18 3 1,alignx left,growx 0");
//---- largeLabel ----
largeLabel.setText("large");
largeLabel.putClientProperty(FlatClientProperties.STYLE_CLASS, "large");
add(largeLabel, "cell 0 19");
//---- largeCheckBox ----
largeCheckBox.setText("Text");
largeCheckBox.putClientProperty(FlatClientProperties.STYLE_CLASS, "large");
add(largeCheckBox, "cell 1 19 3 1,alignx left,growx 0");
//---- largeRadioButton ----
largeRadioButton.setText("Text");
largeRadioButton.putClientProperty(FlatClientProperties.STYLE_CLASS, "large");
add(largeRadioButton, "cell 4 19 3 1,alignx left,growx 0");
//---- defaultLabel ----
defaultLabel.setText("default");
add(defaultLabel, "cell 0 20");
//---- defaultCheckBox ----
defaultCheckBox.setText("Text");
add(defaultCheckBox, "cell 1 20 3 1,alignx left,growx 0");
//---- defaultRadioButton ----
defaultRadioButton.setText("Text");
add(defaultRadioButton, "cell 4 20 3 1,alignx left,growx 0");
//---- mediumLabel ----
mediumLabel.setText("medium");
mediumLabel.putClientProperty(FlatClientProperties.STYLE_CLASS, "medium");
add(mediumLabel, "cell 0 21");
//---- mediumCheckBox ----
mediumCheckBox.setText("Text");
mediumCheckBox.putClientProperty(FlatClientProperties.STYLE_CLASS, "medium");
add(mediumCheckBox, "cell 1 21 3 1,alignx left,growx 0");
//---- mediumRadioButton ----
mediumRadioButton.setText("Text");
mediumRadioButton.putClientProperty(FlatClientProperties.STYLE_CLASS, "medium");
add(mediumRadioButton, "cell 4 21 3 1,alignx left,growx 0");
//---- smallLabel ----
smallLabel.setText("small");
smallLabel.putClientProperty(FlatClientProperties.STYLE_CLASS, "small");
add(smallLabel, "cell 0 22");
//---- smallCheckBox ----
smallCheckBox.setText("Text");
smallCheckBox.putClientProperty(FlatClientProperties.STYLE_CLASS, "small");
add(smallCheckBox, "cell 1 22 3 1,alignx left,growx 0");
//---- smallRadioButton ----
smallRadioButton.setText("Text");
smallRadioButton.putClientProperty(FlatClientProperties.STYLE_CLASS, "small");
add(smallRadioButton, "cell 4 22 3 1,alignx left,growx 0");
//---- miniLabel ----
miniLabel.setText("mini");
miniLabel.putClientProperty(FlatClientProperties.STYLE_CLASS, "mini");
add(miniLabel, "cell 0 23");
//---- miniCheckBox ----
miniCheckBox.setText("Text");
miniCheckBox.putClientProperty(FlatClientProperties.STYLE_CLASS, "mini");
add(miniCheckBox, "cell 1 23 3 1,alignx left,growx 0");
//---- miniRadioButton ----
miniRadioButton.setText("Text");
miniRadioButton.putClientProperty(FlatClientProperties.STYLE_CLASS, "mini");
add(miniRadioButton, "cell 4 23 3 1,alignx left,growx 0");
//---- buttonGroup1 ----
ButtonGroup buttonGroup1 = new ButtonGroup();
buttonGroup1.add(zoom1xButton);

View File

@@ -1,4 +1,4 @@
JFDML JFormDesigner: "7.0.5.0.382" Java: "16" encoding: "UTF-8"
JFDML JFormDesigner: "8.3" encoding: "UTF-8"
new FormModel {
contentType: "form/swing"
@@ -9,7 +9,7 @@ new FormModel {
add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) {
"$layoutConstraints": "insets dialog,hidemode 3"
"$columnConstraints": "[fill][sizegroup 1,center][sizegroup 1,center][sizegroup 1,center]para[sizegroup 2,center][sizegroup 2,center][sizegroup 2,center]0[grow,fill]"
"$rowConstraints": "[]para[][]3[][][][][]unrel[]para[][]3[][][][][]unrel[]"
"$rowConstraints": "[]para[][]3[][][][][]unrel[]para[][]3[][][][][]unrel[]para[][][][][][][]"
} ) {
name: "this"
add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) {
@@ -521,19 +521,140 @@ new FormModel {
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 2 16"
} )
add( new FormComponent( "javax.swing.JLabel" ) {
name: "label39"
"text": "Sizes"
"$client.FlatLaf.styleClass": "h3"
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 0 17 3 1"
} )
add( new FormComponent( "javax.swing.JLabel" ) {
name: "label5"
"text": "JCheckBox"
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 1 18 3 1,alignx left,growx 0"
} )
add( new FormComponent( "javax.swing.JLabel" ) {
name: "label6"
"text": "JRadioButton"
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 4 18 3 1,alignx left,growx 0"
} )
add( new FormComponent( "javax.swing.JLabel" ) {
name: "largeLabel"
"text": "large"
"$client.FlatLaf.styleClass": "large"
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 0 19"
} )
add( new FormComponent( "javax.swing.JCheckBox" ) {
name: "largeCheckBox"
"text": "Text"
"$client.FlatLaf.styleClass": "large"
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 1 19 3 1,alignx left,growx 0"
} )
add( new FormComponent( "javax.swing.JRadioButton" ) {
name: "largeRadioButton"
"text": "Text"
"$client.FlatLaf.styleClass": "large"
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 4 19 3 1,alignx left,growx 0"
} )
add( new FormComponent( "javax.swing.JLabel" ) {
name: "defaultLabel"
"text": "default"
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 0 20"
} )
add( new FormComponent( "javax.swing.JCheckBox" ) {
name: "defaultCheckBox"
"text": "Text"
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 1 20 3 1,alignx left,growx 0"
} )
add( new FormComponent( "javax.swing.JRadioButton" ) {
name: "defaultRadioButton"
"text": "Text"
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 4 20 3 1,alignx left,growx 0"
} )
add( new FormComponent( "javax.swing.JLabel" ) {
name: "mediumLabel"
"text": "medium"
"$client.FlatLaf.styleClass": "medium"
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 0 21"
} )
add( new FormComponent( "javax.swing.JCheckBox" ) {
name: "mediumCheckBox"
"text": "Text"
"$client.FlatLaf.styleClass": "medium"
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 1 21 3 1,alignx left,growx 0"
} )
add( new FormComponent( "javax.swing.JRadioButton" ) {
name: "mediumRadioButton"
"text": "Text"
"$client.FlatLaf.styleClass": "medium"
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 4 21 3 1,alignx left,growx 0"
} )
add( new FormComponent( "javax.swing.JLabel" ) {
name: "smallLabel"
"text": "small"
"$client.FlatLaf.styleClass": "small"
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 0 22"
} )
add( new FormComponent( "javax.swing.JCheckBox" ) {
name: "smallCheckBox"
"text": "Text"
"$client.FlatLaf.styleClass": "small"
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 1 22 3 1,alignx left,growx 0"
} )
add( new FormComponent( "javax.swing.JRadioButton" ) {
name: "smallRadioButton"
"text": "Text"
"$client.FlatLaf.styleClass": "small"
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 4 22 3 1,alignx left,growx 0"
} )
add( new FormComponent( "javax.swing.JLabel" ) {
name: "miniLabel"
"text": "mini"
"$client.FlatLaf.styleClass": "mini"
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 0 23"
} )
add( new FormComponent( "javax.swing.JCheckBox" ) {
name: "miniCheckBox"
"text": "Text"
"$client.FlatLaf.styleClass": "mini"
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 1 23 3 1,alignx left,growx 0"
} )
add( new FormComponent( "javax.swing.JRadioButton" ) {
name: "miniRadioButton"
"text": "Text"
"$client.FlatLaf.styleClass": "mini"
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 4 23 3 1,alignx left,growx 0"
} )
}, new FormLayoutConstraints( null ) {
"location": new java.awt.Point( 0, 0 )
"size": new java.awt.Dimension( 325, 515 )
"size": new java.awt.Dimension( 325, 685 )
} )
add( new FormNonVisual( "javax.swing.ButtonGroup" ) {
name: "buttonGroup1"
}, new FormLayoutConstraints( null ) {
"location": new java.awt.Point( 0, 580 )
"location": new java.awt.Point( 0, 735 )
} )
add( new FormNonVisual( "javax.swing.ButtonGroup" ) {
name: "buttonGroup2"
}, new FormLayoutConstraints( null ) {
"location": new java.awt.Point( 0, 634 )
"location": new java.awt.Point( 0, 790 )
} )
}
}

View File

@@ -1319,6 +1319,14 @@ ViewportUI
[style].small
[style]Button.clearButton
[style]Button.inTextField
[style]CheckBox.large
[style]CheckBox.medium
[style]CheckBox.mini
[style]CheckBox.small
[style]RadioButton.large
[style]RadioButton.medium
[style]RadioButton.mini
[style]RadioButton.small
[style]ToggleButton.inTextField
[style]ToolBar.inTextField
[style]ToolBarSeparator.inTextField