清除Java中的一组单选按钮 [英] Clearing a group of radio buttons in Java

查看:216
本文介绍了清除Java中的一组单选按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个程序,提示用户从四个选项中选择一个选项(来自一组RadioButtons)。

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.

到目前为止,我已经实现了一种方法来实际取消选择无线电按钮并且工作正常(清除变量的值) ,它没有做的是从先前选择的radiobutton中删除黑点。另一方面,同样的方法可以在取消选中和取消选中复选框时正常工作。

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?

这是我的代码:

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


推荐答案

将它们组成一组按钮然后 buttonGroup1.clearSelection();

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

这篇关于清除Java中的一组单选按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆