質問

JPanel.add(ButtonGroup);

Is not working. I MUST add it to a JPanel because I am using tabs. This is getting really frustrating.I hace not found a way yet

役に立ちましたか?

解決

As ButtonGroup is not a component, you cannot add your ButtonGroup to a JPanel. Instead add your buttons to your JPanel, e.g:

JPanel jPanel = new JPanel();
ButtonGroup group = new ButtonGroup();
btn1 = new JRadioButton("btn1 ");btn1.setSelected(true);
btn2 = new JRadioButton("btn2 ");
group.add(btn1 );
group.add(btn2 );

jPanel.add(btn1);
jPanel.add(btn2).

Hope it will be useful.

Thanks

他のヒント

The ButtonGroup class creates only a logical radio button selection group, not a physical one, and is responsible for ensuring that only one button is selected (by deselecting others in the group).

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top