• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

deselect elements belonging to the same ButtonGroup

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Marshal
Posts: 79649
380
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Add the button to the group and don't add it to a visible Component.
 
axel axek
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.


 
axel axek
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 5167
11
Netbeans IDE Opera Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nice

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

Thank you!


....
A life to learn everything about Java is not enough...
 
She's brilliant. She can see what can be and is not limited to what is. And she knows this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic