0

我试图在按下清除按钮时取消选择 JRadio 按钮。我试过谷歌搜索并浏览了很多论坛,我能找到的唯一解决方法是创建一个不可见的按钮,并在按下清除按钮时选择不可见的按钮。我还有其他方法可以使用吗?我的代码如下

public class deselectRadioBtn extends JFrame {
    private JRadioButton[] buttons; // array for JRadio buttons

    public deselectRadioBtn() {
        super("Deselect Radio");
        for (int nbrOfButtons = 0; nbrOfButtons < options.length; nbrOfButtons++) {

            //create new JRadioButtons and labels and add ( ) around label
            buttons[nbrOfButtons] = new JRadioButton(( nbrOfButtons +    radioLabel[nbrOfButtons] ));

        //add buttons to eastPanel
        rightPanel.add(options[nbrOfButtons]);
    }//end  for (JRadio)



    //Create a ButtonGroup object, add buttons to the group
    ButtonGroup optionSelect = new ButtonGroup();
    optionSelect.add(buttons[0]);
    optionSelect.add(buttons[1]);
    optionSelect.add(buttons[2]);
    optionSelect.add(buttons[3]);
}

这只是一段代码,我还没有包含完整的代码。

4

1 回答 1

1

使用ButtonGroup.clearSelection().

于 2013-07-18T11:34:11.437 回答