This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes radio button question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "radio button question" Watch "radio button question" New topic

radio button question

miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
i've a buttongroup; is there a fast way of knowing which radiobutton is selected, instead of
if radio1.isSelected() this
if radio2.isSelected() that


java amateur
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
you can do this


which will return the specific actionCommand() of the radioButton (if set),
but then you'd probably test the return in a bunch of if's anyway, so you're
no better off.

if you have actionListeners added to each radioButton, another option might
be to create a class field
JRadioButton selection;
and in actionPerformed() include
selection = (JRadioButton)actionEvent.getSource();
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
your idea sounds good, Michael
before i read your post i wrote:

and then used tipoLancamento elsewhere in my code

thank you!
I agree. Here's the link:
subject: radio button question
It's not a secret anymore!