mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-11 06:27:13 -06:00
Testing: added "size variant" combobox to control bar if Aqua or Nimbus LaF are active
This commit is contained in:
@@ -142,6 +142,8 @@ public class FlatTestFrame
|
||||
if( scaleFactor != null )
|
||||
scaleFactorComboBox.setSelectedItem( scaleFactor );
|
||||
|
||||
updateSizeVariantComboBox();
|
||||
|
||||
// register F1, F2, ... keys to switch to Light, Dark or other LaFs
|
||||
registerSwitchToLookAndFeel( KeyEvent.VK_F1, FlatLightLaf.class.getName() );
|
||||
registerSwitchToLookAndFeel( KeyEvent.VK_F2, FlatDarkLaf.class.getName() );
|
||||
@@ -198,6 +200,9 @@ public class FlatTestFrame
|
||||
// enable/disable scale factor combobox
|
||||
updateScaleFactorComboBox();
|
||||
|
||||
// show/hide size variant combobox
|
||||
updateSizeVariantComboBox();
|
||||
|
||||
// this is necessary because embedded JOptionPane's "steal" the default button
|
||||
getRootPane().setDefaultButton( closeButton );
|
||||
} );
|
||||
@@ -401,6 +406,23 @@ public class FlatTestFrame
|
||||
scaleFactorComboBox.setEnabled( !UIScale.isSystemScalingEnabled() && UIManager.getLookAndFeel() instanceof FlatLaf );
|
||||
}
|
||||
|
||||
private void sizeVariantChanged() {
|
||||
String sel = (String) sizeVariantComboBox.getSelectedItem();
|
||||
String sizeVariant = "default".equals( sel ) ? null : sel;
|
||||
|
||||
updateComponentsRecur( content, (c, type) -> {
|
||||
if( c instanceof JComponent )
|
||||
((JComponent)c).putClientProperty( "JComponent.sizeVariant", sizeVariant );
|
||||
} );
|
||||
}
|
||||
|
||||
private void updateSizeVariantComboBox() {
|
||||
LookAndFeel lookAndFeel = UIManager.getLookAndFeel();
|
||||
boolean visible = lookAndFeel instanceof NimbusLookAndFeel ||
|
||||
"com.apple.laf.AquaLookAndFeel".equals( lookAndFeel.getClass().getName() );
|
||||
sizeVariantComboBox.setVisible( visible );
|
||||
}
|
||||
|
||||
private void updateComponentsRecur( Container container, BiConsumer<Component, String> action ) {
|
||||
for( Component c : container.getComponents() ) {
|
||||
if( c instanceof JPanel || c instanceof JDesktopPane ) {
|
||||
@@ -471,6 +493,7 @@ public class FlatTestFrame
|
||||
explicitColorsCheckBox = new JCheckBox();
|
||||
backgroundCheckBox = new JCheckBox();
|
||||
opaqueTriStateCheckBox = new TriStateCheckBox();
|
||||
sizeVariantComboBox = new JComboBox<>();
|
||||
closeButton = new JButton();
|
||||
themesPanel = new IJThemesPanel();
|
||||
|
||||
@@ -508,6 +531,7 @@ public class FlatTestFrame
|
||||
"[fill]" +
|
||||
"[fill]" +
|
||||
"[fill]" +
|
||||
"[fill]" +
|
||||
"[grow,fill]" +
|
||||
"[button,fill]",
|
||||
// rows
|
||||
@@ -573,9 +597,20 @@ public class FlatTestFrame
|
||||
opaqueTriStateCheckBox.addActionListener(e -> opaqueChanged());
|
||||
buttonBar.add(opaqueTriStateCheckBox, "cell 7 0");
|
||||
|
||||
//---- sizeVariantComboBox ----
|
||||
sizeVariantComboBox.setModel(new DefaultComboBoxModel<>(new String[] {
|
||||
"mini",
|
||||
"small",
|
||||
"default",
|
||||
"large"
|
||||
}));
|
||||
sizeVariantComboBox.setSelectedIndex(2);
|
||||
sizeVariantComboBox.addActionListener(e -> sizeVariantChanged());
|
||||
buttonBar.add(sizeVariantComboBox, "cell 8 0");
|
||||
|
||||
//---- closeButton ----
|
||||
closeButton.setText("Close");
|
||||
buttonBar.add(closeButton, "cell 9 0");
|
||||
buttonBar.add(closeButton, "cell 10 0");
|
||||
}
|
||||
dialogPane.add(buttonBar, BorderLayout.SOUTH);
|
||||
dialogPane.add(themesPanel, BorderLayout.EAST);
|
||||
@@ -596,6 +631,7 @@ public class FlatTestFrame
|
||||
private JCheckBox explicitColorsCheckBox;
|
||||
private JCheckBox backgroundCheckBox;
|
||||
private TriStateCheckBox opaqueTriStateCheckBox;
|
||||
private JComboBox<String> sizeVariantComboBox;
|
||||
private JButton closeButton;
|
||||
private IJThemesPanel themesPanel;
|
||||
// JFormDesigner - End of variables declaration //GEN-END:variables
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
JFDML JFormDesigner: "7.0.0.0.194" Java: "13.0.1" encoding: "UTF-8"
|
||||
JFDML JFormDesigner: "7.0.1.0.272" Java: "13.0.2" encoding: "UTF-8"
|
||||
|
||||
new FormModel {
|
||||
contentType: "form/swing"
|
||||
@@ -21,7 +21,7 @@ new FormModel {
|
||||
} )
|
||||
add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) {
|
||||
"$layoutConstraints": "insets dialog"
|
||||
"$columnConstraints": "[fill][fill][fill][fill][fill][fill][fill][fill][grow,fill][button,fill]"
|
||||
"$columnConstraints": "[fill][fill][fill][fill][fill][fill][fill][fill][fill][grow,fill][button,fill]"
|
||||
"$rowSpecs": "[fill]"
|
||||
} ) {
|
||||
name: "buttonBar"
|
||||
@@ -105,11 +105,25 @@ new FormModel {
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 7 0"
|
||||
} )
|
||||
add( new FormComponent( "javax.swing.JComboBox" ) {
|
||||
name: "sizeVariantComboBox"
|
||||
"model": new javax.swing.DefaultComboBoxModel {
|
||||
selectedItem: "mini"
|
||||
addElement( "mini" )
|
||||
addElement( "small" )
|
||||
addElement( "default" )
|
||||
addElement( "large" )
|
||||
}
|
||||
"selectedIndex": 2
|
||||
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "sizeVariantChanged", false ) )
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 8 0"
|
||||
} )
|
||||
add( new FormComponent( "javax.swing.JButton" ) {
|
||||
name: "closeButton"
|
||||
"text": "Close"
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 9 0"
|
||||
"value": "cell 10 0"
|
||||
} )
|
||||
}, new FormLayoutConstraints( class java.lang.String ) {
|
||||
"value": "South"
|
||||
|
||||
Reference in New Issue
Block a user