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

Problem with JRadioButton

Mihir Sen

Joined: Jul 16, 2001
Posts: 2
hi friends,
I am developing one ExamSimulator. at a time one question and three options will display on a screen.
I have three JRadioButtons and i have added those three in one ButtonGroup so that at a time only one will get selected.Now while displaying next question i want all the options should be unchecked. how to achieve this?
i am using setSelected(false) method of JRadioButton. but i am not getting the expected result.
expecting your help
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15302

I believe that the way a JRadio Button works is one always has to be selected. I may be wrong, but in my experience with them, it seems that one radio button has to be the default answer. I would like to be proven wrong though.

GenRocket - Experts at Building Test Data
Manfred Leonhardt
Ranch Hand

Joined: Jan 09, 2001
Posts: 1492
Hi Mihir,
Gregg's logic is correct. However, humans are easily fooled. The following code will perform what you want.

I agree. Here's the link:
subject: Problem with JRadioButton
It's not a secret anymore!