wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes check box group Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "check box group" Watch "check box group" New topic
Author

check box group

Yasir Qureshi
Ranch Hand

Joined: Apr 27, 2001
Posts: 44
How should i use checkboxgroup in swing.
Yasir
Rene Liebmann
Ranch Hand

Joined: May 02, 2002
Posts: 196
Hi
If you are looking to the API, then you will find following little sample code:

As for a short description, imagine you have a bundle of Checkboxes, which belong together, like on and off or some colors. Anyway, there can be only one selection and not several. If you don't want to take RadioButtons with a ButtonGroup, then you can take Checkboxes with a CheckBoxGroup. This group manages, that there can be only one selection in its members.
Yasir Qureshi
Ranch Hand

Joined: Apr 27, 2001
Posts: 44
thanks a lot but gave solution in awt.
I have written following code, but its allowing multiple checkbox to be selected.
ButtonGroup bg=new ButtonGroup();
JButton b1=new JButton("b1");
JButton b2=new JButton("b2");
JButton b3=new JButton("b3");
bg.add(b1);bg.add(b2);bg.add(b3);
How could i allow single box to be selected.
i.e equivalent of button.setCheckboxGroup() in swing.
Yasir
Rene Liebmann
Ranch Hand

Joined: May 02, 2002
Posts: 196
Sorry, I forgot that you need a solution for Swing.
Here is the code that you need:
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: check box group