Getting and Setting the State of a JCheckbox Component
import javax.swing.JCheckBox;
publicclass Main {
publicstaticvoid main(String[] argv) throws Exception {
JCheckBox checkbox = new JCheckBox();
// Get the current state of the checkbox
boolean b = checkbox.isSelected();
// Set the state of the checkbox to off
checkbox.setSelected(false);
// Set the state of the checkbox to on
checkbox.setSelected(true);
}
}