Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

radio button question

 
miguel lisboa
Ranch Hand
Posts: 1281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
your idea sounds good, Michael
before i read your post i wrote:


and then used tipoLancamento elsewhere in my code

thank you!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic