How to manage two JRadioButtons in java so that only one of them can be selected at a time

后端 未结 2 1736
没有蜡笔的小新
没有蜡笔的小新 2020-12-29 23:24

How to manage two JRadioButtons in java so that only one of them can be selected at a time? Is there any method in java to take care of this or you need to build your own lo

2条回答
  •  北海茫月
    2020-12-30 00:05

    My java is rusty but if i remember correctly you have to use the ButtonGroup class. Add your radio buttons to ButtonGroup object. I think it will look like this.

    ButtonGroup buttonGroup = new ButtonGroup();
    buttonGroup.add(new JRadioButton('Label', false));
    buttonGroup.add(new JRadioButton('Label2', true));
    

    Hope this helps. I have abandoned Java years ago.

提交回复
热议问题