简体   繁体   中英

Set Panel to display when CheckBox is checked? (Java)

I have a checkbox and a panel. When the checkbox is checked, I would like for the panel to display. If the user un-checks it, I want the panel to go back to false visibility.

How would I accomplish this?

If you are using Swing as the GUI toolkit. The solution is simple.

Below is the Swing implementation

private JCheckBox box;
box.addChangeListener(new ChangeListener() {

            public void stateChanged(ChangeEvent arg0) {
                jpanel.setVisible(box.isSelected());
            }
        });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM