Clearing a group of radio buttons in Java

2019-02-24 19:26发布

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条回答
看我几分像从前
2楼-- · 2019-02-24 19:46

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

查看更多
登录 后发表回答