Reputation: 29
I am using a content pane with gridbag layout and i have created 3 JRadioButtons
. I have an actionlistener
that makes a command when they are press and in a different method I handle the actions.
I tried buttonname.setSelected(false);
and it does not work. I searched about this and people were talking about button groups so I created one and added the buttons to the group like this:
ButtonGroup group = new ButtonGroup();
group.add(color1);
group.add(color2);
group.add(color3);
I put that in my pane thing where I add components to pane after I added the buttons with pane.add(buttonname, c);
How do I group.clearSelection()
or whatever the command is from my action handling method?
Upvotes: 3
Views: 485
Reputation: 44834
This is from the Javadocs of ButtonGroup
This class is used to create a multiple-exclusion scope for a set of buttons. Creating a set of buttons with the same ButtonGroup object means that turning "on" one of those buttons turns off all other buttons in the group. A ButtonGroup can be used with any set of objects that inherit from AbstractButton.
So it would seem that you do not need to do anything.
Upvotes: 2