我的复选框有问题。当我尝试读取它的状态时,它的名称无法解析。
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");
}}
答案 0 :(得分:1)
答案 1 :(得分:0)
//add this
checkbox1.setSelected(true);
将您的Checkbox功能更改为此代码:
//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);