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 JRadioButton : Deselecting Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JRadioButton : Deselecting" Watch "JRadioButton : Deselecting" New topic

JRadioButton : Deselecting

Vikram Deshmukh

Joined: Apr 22, 2000
Posts: 29
Hi Group,
I have a button group. Within that, I am having 2 JRadioButtons. One of them is selected. On click of some JButton, i want to de-select that radio button.
On handler of JButton i wrote, but it doesnt work.
Does anyone has any remedy over this ?
Nathan Pruett

Joined: Oct 18, 2000
Posts: 4121

At least one button in a ButtonGroup must be selected. If you read the API for ButtonGroup it gives you this workaround...

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.

Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Chantal Ackermann
Ranch Hand

Joined: Sep 28, 2000
Posts: 508
wouldn't it be possible to add the "some JButton" to the button group?
I agree. Here's the link:
subject: JRadioButton : Deselecting
It's not a secret anymore!