File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes deselect elements belonging to the same ButtonGroup Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "deselect elements belonging to the same ButtonGroup" Watch "deselect elements belonging to the same ButtonGroup" New topic
Author

deselect elements belonging to the same ButtonGroup

axel axek
Greenhorn

Joined: May 28, 2009
Posts: 20
Hi

Is there any way to deselect all CheckBoxes belonging to the same ButtonGroup?

Quote from javax.swing.ButtonGroup
"Initially, all buttons in the group are unselected. Once any button is selected, one button is always selected in the group. There is no way to turn a button programmatically to "off", in order to clear the button group. To give the appearance of "none selected", add an invisible radio button to the group and then programmatically select that button to turn off all the displayed radio buttons. For example, a normal button with the label "none" could be wired to select the invisible radio button."



...so....it may be possible by using an "invisible" check box?.... I just do not see how....

Any ideas?

Best Regards,
Alex
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38107
    
  22
Add the button to the group and don't add it to a visible Component.
axel axek
Greenhorn

Joined: May 28, 2009
Posts: 20
and how would that button be selected if it is invisible?

...i mean...what dependencies could be set in order to clear the ButtonGroup when clicking on a selected checkbox?
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4523
    
    5

Why are you using an old obsolete version of Java? Update to 1.6 and you have ButtonGroup#clearSelection()
Clears the selection such that none of the buttons in the ButtonGroup are selected.


luck, db
There are no new questions, but there may be new answers.
axel axek
Greenhorn

Joined: May 28, 2009
Posts: 20
ok...i know that there is such a feature.....but....the question is....what would trigger the clearSelection() on the button group?

Supposing that a GUI only has 3 check Boxes belonging to the same button Group, clicking on one of them will select the desire check Box, but when clicking again on the same check box in order to deselect it, it won't...
...how can the clearSelection() method be used in this case? (you can't trigger it by a check box in this case.....)
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4523
    
    5

Supposing that a GUI only has 3 check Boxes belonging to the same button Group, clicking on one of them will select the desire check Box, but when clicking again on the same check box in order to deselect it, it won't...

It can. Use an extended ButtonGroup and override setSelected(...) to produce the desired behavior.
axel axek
Greenhorn

Joined: May 28, 2009
Posts: 20
Nice

I haven't thought of it this way...

Thank you!


....
A life to learn everything about Java is not enough...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: deselect elements belonging to the same ButtonGroup
 
Similar Threads
JRadioButtons in applet
Unselect all buttons in a JToggleButton ButtonGroup
setState() with JRadioButton
JRadioButton : Deselecting
RadioGroup with JRadioButton