取消选中Java中的复选框 [英] uncheck checkboxes in java
问题描述
在我的程序中,无论何时调用此方法,我都希望取消选中所有复选框.有人可以解释为什么它不起作用吗?每当我调用此方法时,仍会选中复选框.
In my program, I want to uncheck all the checkboxes whenever this method is called. Can someone explain why it isn't working? Whenever I call this method the checkboxes are still selected.
private void nextQuestionButtonActionPerformed(java.awt.event.ActionEvent evt) {
clearOptions();
}
public void clearOptions ()
{
//Make sure the check boxes are not checked
optionA.setSelected(false);
optionB.setSelected(false);
optionC.setSelected(false);
optionD.setSelected(false);
}
推荐答案
首先,您需要将所有复选框的代码置于例如状态更改方法&的顶部.之后,取消选中该复选框,您可以创建一个变量,例如state&将变量值设置为false&之后,您可以调用 checkbox.setSelected(false);
或 boolean state = false;.CheckBox.setSelected(state);
就是这样!
first of all you need to bring all of the check box s code on the top of your for example state change method & after that for uncheck the check box you can make a variable like state & put the variable value on false & after that you can call the checkbox.setSelected(false);
or boolean state = false;
CheckBox.setSelected(state);
that's it !!!
这篇关于取消选中Java中的复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!