File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes deselecting radio button Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "deselecting radio button" Watch "deselecting radio button" New topic

deselecting radio button

Ikram Soomro
Ranch Hand

Joined: Oct 20, 2001
Posts: 42
If we select a radio button than can we deselect it? just like in check box if we select a checkbox than we can deselect it by again click it.
My question is that how can i deselect radio button? When I click on selected radio button than its selection should clear.
Darin Niard
Ranch Hand

Joined: Jun 08, 2004
Posts: 118
That isn't really how they work... If you need to deselect a radio button, then you probably shouldn't be using radio buttons, but checkboxes instead.

If you really want to do this, just attach a listener to the buttons and .setSelected(false) on the source.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
Ikram Soomro
Ranch Hand

Joined: Oct 20, 2001
Posts: 42
Thank You Michael Dunn!
Perfect solution!
I agree. Here's the link:
subject: deselecting radio button
It's not a secret anymore!