Reputation: 151
I have a problem with my checkbox. When I try to read the state of it the name of it can not be resolved.
JCheckBox checkbox1 = new JCheckBox("Test");
checkbox1.setBounds(6, 59, 121, 23);
frmTree.getContentPane().add(checkbox1);
public void Checkbox() {
if (checkbox1.isSelected()) {
Sytem.out.println("Selected");
}}
Upvotes: 0
Views: 369
Reputation: 1482
//add this
checkbox1.setSelected(true);
Change your Checkbox function to this code:
//Try using boolean in your condition
//Get the selection state of the checkbox
boolean selected = checkbox1.isSelected();
if (selected) {
System.out.println("Selected.");
} else {
System.out.println("Not Selected.");
}
frmTree.getContentPane().add(checkbox1);
Upvotes: 0