aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes radio buttons and button groups Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "radio buttons and button groups" Watch "radio buttons and button groups" New topic
Author

radio buttons and button groups

Mike Johns
Greenhorn

Joined: Mar 01, 2001
Posts: 10
I have 5 radio buttons I have added to a button group, initially they are all false. I want to reset them all to false after one run through system. The method setSelected(false) is not resetting my radio buttons to false and therefore not clearing them. Any ideas?
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
The method you are looking for is part of CheckboxGroup, not Checkbox its self. You can do it like this:
<PRE>
CheckboxGroup c = new CheckboxGroup();
...
c.setSelectedCheckbox(null); // sets all Checkboxes in this group to false
</PRE>

HTH
Mike Johns
Greenhorn

Joined: Mar 01, 2001
Posts: 10
The problem is CheckboxGroup will not let me add a JRadioButton. Do you know of anything that will work will JRadioButton?
Thanks for trying
Glen Tanner
Ranch Hand

Joined: Apr 16, 1999
Posts: 147

This is a bit of a hack, but if you add an invisible button to the group, you can select it to clear all the others...
Mike Johns
Greenhorn

Joined: Mar 01, 2001
Posts: 10
Glen,
It may be a hack, but it works!
Thanks,
Mike
Glen Tanner
Ranch Hand

Joined: Apr 16, 1999
Posts: 147

Cool! I'm glad it worked.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: radio buttons and button groups