aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes model for group of radio buttons Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "model for group of radio buttons" Watch "model for group of radio buttons" New topic
Author

model for group of radio buttons

sudheer kiran
Ranch Hand

Joined: Jun 26, 2008
Posts: 237

hi all,

i have a set of radio buttons. what is the class which represents model for set of radio buttons.
how can i get a selected radio button from a group.
i am expecting one like a DefaultComboBoxModel for combo boxes.
please let me know if any is available.





Sudheer
SCWCD, SCJP 5
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19693
    
  20

You need ButtonGroup to make the radio buttons work together. That class doesn't have a method to get the selected radio button though, only the ButtonModel of the selected button. You'll need to check each of the radio buttons to see which one isSelected(). Storing them in an array may help you.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
sudheer kiran
Ranch Hand

Joined: Jun 26, 2008
Posts: 237

thanks for the reply.
i have one more question.
we set objects to combox so that when call getSelected i will get object.
but i case of radio buttons i can't set a object to it ,i can set only string value am i right?

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38812
    
  23
Have you been through the JRadioButton constructors? There doesn't appear to be one taking Object as a parameter type. You could try an Action, as Rob shows in this old thread.
Jerry Goldsmith
Ranch Hand

Joined: Nov 29, 2006
Posts: 53
Here are a couple of snippets of button group code. Hope this helps.

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38812
    
  23
I hope you are not using the action command in a big bank of if-elses.

I am not certain, because I haven't seen all your code, but I am not convinced that "open" and "close" are suitable for radio buttons. I would have thought that is more appropriate for an ordinary button.
Jerry Goldsmith
Ranch Hand

Joined: Nov 29, 2006
Posts: 53
I'm simply displaying the actionCommand string in a message window opened by the action listener.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38812
    
  23
That sounds better.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: model for group of radio buttons