This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma 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


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "radio button question" Watch "radio button question" New topic
Author

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

TiA


java amateur
Michael Dunn
Ranch Hand

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

group.getSelection().getActionCommand();

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: http://aspose.com/file-tools
 
subject: radio button question
 
It's not a secret anymore!