I use:
CheckboxGroup cg = new CheckboxGroup();
Checkbox c1 = new Checkbox("A", false, cg);
Checkbox c2 = new Checkbox("B", false, cg);
Checkbox c3 = new Checkbox("C", true, cg);
创建一组三个复选框。现在,我想检查其中哪一个被检查了。我用:
if (c1.isSelected()) { }
但这给出了The method isSelected() is undefined for the type Checkbox
...推荐的解决方案是将强制转换添加到 c1,我这样做,它给出了Cannot cast from Checkbox to AbstractButton
...同样,我如何检查复选框是否被选中?
使用 getState()
boolean checked = c1.getState();
if(c1.getState()) {
//c1 is checked
} else if (c2.getState()) {
//
}
OR
Checkbox cb = cg.getSelectedCheckbox();
if(null != cb) {
//not checked
} else {
System.out.println(cb.getLabel() + " is checked");
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)