user1176922
user1176922

Reputation: 93

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?

Upvotes: 0

Views: 1229

Answers (1)

Chan
Chan

Reputation: 2641

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());
            }
        });

Upvotes: 1

Related Questions