Clearing a group of radio buttons in Java

吃可爱长大的小学妹 提交于 2019-12-01 22:16:06

问题


I have a program which prompts users to select a choice out of four options (from a group of RadioButtons).

Once the user has made a choice, he/she clicks a button and then receives a message. After closing the window, the user will go back to the first window and make a new selection if desired. What I want is for the radiobuttons to be totally clear.

So far I have implemented a method to actually unselect the radiobuttons and works well (clears the values of the variables), what it doesn't do is to remove the black spot from the previously selected radiobutton. In the other hand this same method works fine with unselecting and unchecking checkboxes.

Any tip to fix this little issue?

Here's my code:

public void clean() {
    jRadioButton1.setSelected(false);
    jRadioButton2.setSelected(false);
    jRadioButton3.setSelected(false);
    jRadioButton4.setSelected(false);
    jCheckBox1.setSelected(false);
    jCheckBox2.setSelected(false);
}

回答1:


make them group of buttons and then buttonGroup1.clearSelection();



来源:https://stackoverflow.com/questions/15080256/clearing-a-group-of-radio-buttons-in-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!