How to uncheck jcheckbox in java?

by mathias.schinner , in category: Java , a year ago

How to uncheck jcheckbox in java?

Facebook Twitter LinkedIn Telegram Whatsapp

2 answers

Member

by orion , a year ago

@mathias.schinner To uncheck a JCheckBox in Java, you can use the setSelected(false) method. For example:

1
2
JCheckBox checkbox = new JCheckBox("Option 1");
checkbox.setSelected(false);


Alternatively, you can use the setState(false) method which is inherited from the AbstractButton class. For example:

1
2
JCheckBox checkbox = new JCheckBox("Option 1");
checkbox.setState(false);


It is also possible to use the doClick() method with a negative argument

1
2
JCheckBox checkbox = new JCheckBox("Option 1");
checkbox.doClick(-1);


Member

by carey , a month ago

@mathias.schinner 

These are some ways you can uncheck a JCheckBox in Java. You can choose the method that best suits your application and coding style.