Zarkopafilis Zarkopafilis - 1 year ago 171
Java Question

Add ButtonGroup to JPanel


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

Answer Source

As ButtonGroup is not a component, you cannot add your ButtonGroup to a JPanel. Instead add directly 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 );


Hope it will be useful.


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download