FlatTestFrame: added "enabled" checkbox to allow enable/disable all components

This commit is contained in:
Karl Tauber
2019-08-29 18:44:09 +02:00
parent 0d5a963599
commit 9c1fa1d802
4 changed files with 62 additions and 35 deletions

View File

@@ -62,14 +62,6 @@ public class FlatContainerTest
}
}
private void enabledChanged() {
boolean enabled = enabledCheckBox.isSelected();
tabbedPane1.setEnabled( enabled );
tabbedPane2.setEnabled( enabled );
tabbedPane3.setEnabled( enabled );
tabbedPane4.setEnabled( enabled );
}
private void initComponents() {
// JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents
JPanel panel9 = new JPanel();
@@ -97,7 +89,6 @@ public class FlatContainerTest
tabScrollCheckBox = new JCheckBox();
hasFullBorderCheckBox = new JCheckBox();
moreTabsCheckBox = new JCheckBox();
enabledCheckBox = new JCheckBox();
CellConstraints cc = new CellConstraints();
//======== this ========
@@ -245,13 +236,6 @@ public class FlatContainerTest
moreTabsCheckBox.setMnemonic('M');
moreTabsCheckBox.addActionListener(e -> moreTabsChanged());
panel9.add(moreTabsCheckBox, cc.xy(1, 9, CellConstraints.LEFT, CellConstraints.DEFAULT));
//---- enabledCheckBox ----
enabledCheckBox.setText("enabled");
enabledCheckBox.setSelected(true);
enabledCheckBox.setMnemonic('E');
enabledCheckBox.addActionListener(e -> enabledChanged());
panel9.add(enabledCheckBox, cc.xy(3, 9, CellConstraints.LEFT, CellConstraints.DEFAULT));
}
add(panel9, "cell 0 0");
// JFormDesigner - End of component initialization //GEN-END:initComponents
@@ -265,6 +249,5 @@ public class FlatContainerTest
private JCheckBox tabScrollCheckBox;
private JCheckBox hasFullBorderCheckBox;
private JCheckBox moreTabsCheckBox;
private JCheckBox enabledCheckBox;
// JFormDesigner - End of variables declaration //GEN-END:variables
}

View File

@@ -186,26 +186,12 @@ new FormModel {
"gridY": 9
"hAlign": sfield com.jgoodies.forms.layout.CellConstraints LEFT
} )
add( new FormComponent( "javax.swing.JCheckBox" ) {
name: "enabledCheckBox"
"text": "enabled"
"selected": true
"mnemonic": 69
auxiliary() {
"JavaCodeGenerator.variableLocal": false
}
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "enabledChanged", false ) )
}, new FormLayoutConstraints( class com.jgoodies.forms.layout.CellConstraints ) {
"gridX": 3
"gridY": 9
"hAlign": sfield com.jgoodies.forms.layout.CellConstraints LEFT
} )
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 0 0"
} )
}, new FormLayoutConstraints( null ) {
"location": new java.awt.Point( 0, 0 )
"size": new java.awt.Dimension( 400, 300 )
"size": new java.awt.Dimension( 400, 400 )
} )
}
}

View File

@@ -21,6 +21,8 @@ import java.awt.event.KeyEvent;
import java.util.prefs.Preferences;
import javax.swing.*;
import javax.swing.plaf.ColorUIResource;
import javax.swing.plaf.metal.MetalLookAndFeel;
import com.formdev.flatlaf.util.SystemInfo;
import net.miginfocom.swing.*;
/**
@@ -69,6 +71,8 @@ public class FlatTestFrame
lafModel.addElement( new LafInfo( "Flat Light", FlatLightLaf.class.getName() ) );
lafModel.addElement( new LafInfo( "Flat Dark", FlatDarkLaf.class.getName() ) );
lafModel.addElement( new LafInfo( "Flat Test", FlatTestLaf.class.getName() ) );
lafModel.addElement( new LafInfo( "Flat IntelliJ", FlatIntelliJLaf.class.getName() ) );
lafModel.addElement( new LafInfo( "Flat Darcula", FlatDarculaLaf.class.getName() ) );
UIManager.LookAndFeelInfo[] lookAndFeels = UIManager.getInstalledLookAndFeels();
for( UIManager.LookAndFeelInfo lookAndFeel : lookAndFeels ) {
@@ -96,6 +100,12 @@ public class FlatTestFrame
registerSwitchToLookAndFeel( KeyEvent.VK_F1, FlatLightLaf.class.getName() );
registerSwitchToLookAndFeel( KeyEvent.VK_F2, FlatDarkLaf.class.getName() );
registerSwitchToLookAndFeel( KeyEvent.VK_F3, FlatTestLaf.class.getName() );
registerSwitchToLookAndFeel( KeyEvent.VK_F4, FlatIntelliJLaf.class.getName() );
registerSwitchToLookAndFeel( KeyEvent.VK_F5, FlatDarculaLaf.class.getName() );
registerSwitchToLookAndFeel( KeyEvent.VK_F7, MetalLookAndFeel.class.getName() );
if( SystemInfo.IS_WINDOWS )
registerSwitchToLookAndFeel( KeyEvent.VK_F8, "com.sun.java.swing.plaf.windows.WindowsLookAndFeel" );
// register ESC key to close frame
((JComponent)getContentPane()).registerKeyboardAction(
@@ -218,6 +228,35 @@ public class FlatTestFrame
contentPanel.repaint();
}
private void enabledChanged() {
enabledDisable( content, enabledCheckBox.isSelected() );
}
private void enabledDisable( Container container, boolean enabled ) {
for( Component c : container.getComponents() ) {
if( c instanceof JPanel ) {
enabledDisable( (JPanel) c, enabled );
continue;
}
c.setEnabled( enabled );
if( c instanceof JScrollPane ) {
Component view = ((JScrollPane)c).getViewport().getView();
if( view != null )
view.setEnabled( enabled );
} else if( c instanceof JTabbedPane ) {
JTabbedPane tabPane = (JTabbedPane)c;
int tabCount = tabPane.getTabCount();
for( int i = 0; i < tabCount; i++ ) {
Component tab = tabPane.getComponentAt( i );
if( tab != null )
tab.setEnabled( enabled );
}
}
}
}
private void initComponents() {
// JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents
dialogPane = new JPanel();
@@ -226,6 +265,7 @@ public class FlatTestFrame
lookAndFeelComboBox = new JComboBox<>();
explicitColorsCheckBox = new JCheckBox();
rightToLeftCheckBox = new JCheckBox();
enabledCheckBox = new JCheckBox();
closeButton = new JButton();
//======== this ========
@@ -256,6 +296,7 @@ public class FlatTestFrame
"[fill]" +
"[fill]" +
"[fill]" +
"[fill]" +
"[grow,fill]" +
"[button,fill]",
// rows
@@ -277,9 +318,16 @@ public class FlatTestFrame
rightToLeftCheckBox.addActionListener(e -> rightToLeftChanged());
buttonBar.add(rightToLeftCheckBox, "cell 2 0");
//---- enabledCheckBox ----
enabledCheckBox.setText("enabled");
enabledCheckBox.setMnemonic('E');
enabledCheckBox.setSelected(true);
enabledCheckBox.addActionListener(e -> enabledChanged());
buttonBar.add(enabledCheckBox, "cell 3 0");
//---- closeButton ----
closeButton.setText("Close");
buttonBar.add(closeButton, "cell 4 0");
buttonBar.add(closeButton, "cell 5 0");
}
dialogPane.add(buttonBar, BorderLayout.SOUTH);
}
@@ -294,6 +342,7 @@ public class FlatTestFrame
private JComboBox<LafInfo> lookAndFeelComboBox;
private JCheckBox explicitColorsCheckBox;
private JCheckBox rightToLeftCheckBox;
private JCheckBox enabledCheckBox;
private JButton closeButton;
// JFormDesigner - End of variables declaration //GEN-END:variables

View File

@@ -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][grow,fill][button,fill]"
"$columnConstraints": "[fill][fill][fill][fill][grow,fill][button,fill]"
"$rowSpecs": "[fill]"
} ) {
name: "buttonBar"
@@ -50,11 +50,20 @@ new FormModel {
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 2 0"
} )
add( new FormComponent( "javax.swing.JCheckBox" ) {
name: "enabledCheckBox"
"text": "enabled"
"mnemonic": 69
"selected": true
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "enabledChanged", false ) )
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 3 0"
} )
add( new FormComponent( "javax.swing.JButton" ) {
name: "closeButton"
"text": "Close"
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 4 0"
"value": "cell 5 0"
} )
}, new FormLayoutConstraints( class java.lang.String ) {
"value": "South"