• Post Reply Bookmark Topic Watch Topic
  • New Topic

JRadioButton question

 
Raj Medha
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This might be a simple question for many of you.
I'm a beginner in Swing...
I have a menu with 4 option (4 RadionButton). What would be the code to know which one has selected. the screen has a OK key . I need to know which Radiobutton has selected when I press the OK key. Appreciate your input.
thanks
Raj
 
Wayne L Johnson
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can call "isSelected()" on each radio button in turn; at most one will return "true".
 
Raj Medha
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Wayne for your help !! it worked !!
Raj
 
Cathy Song
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

Since the radio buttons are grouped as ButtonGroup why cant you just call a method on the group to determine which radio button is selected?

Thanks,
Cathy.
 
Joe Ess
Bartender
Posts: 9361
11
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, Cathy, calling ButtonGroup.getSelection() would be much easier than iterating through all the radio buttons.
 
Cathy Song
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Joe.

-Cathy.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!