Click to See Complete Forum and Search --> : Making multiple radio buttons in a JTable Frame


laneh
September 22nd, 2000, 02:51 PM
I saw the code for the multiple radio buttons on the website, but my question is how would i make it dynamic? For instance, one cell has 2 radio buttons and the next has 4 buttons, etc. I trying to figure this out because I'm working on a program that when a certain button is pressed, depending on the button that is pressed, a different thing will happen, so I would also need a way to get the id/text of the button that was pressed.
I'm not expecting the entire code, maybe just a little bit to get me started on how to do it.

"There are no facts, only interpretations."
-Friedrich Nietzsche

Phill
September 24th, 2000, 01:19 AM
Hi
You can add several Checkboxes to a
CheckboxGroup and then add this group to a
Panel, and then add the Panel to the GUI. To add each one to a group do this:

cb1 = new Checkbox("Label", thegroup, false);
panelone.add(cb1);//add the first checkbox to the Panel
add(panelone);// add the first panel to the GUI




To retrieve the selected Checkbox use:
getSelectedCheckbox() in the CheckboxGroup
class, you must use this inside the listener
method which is "itemStateChanged(ItemEvent e)"

if you want the Label off the Checkbox,
you can retrieve it like this:

public void itemStateChanged(ItemEvent e){
String selected = thegroup.getSelectedCheckbox().getLabel();
//then you can do somthing with it like this
if(selected == "First")
doSomething();
else
doSomethingElse();
}




Hope this has helped.
If you need more help with this you
can email me at
kashmir@zip.com.au
Phill.

Pleeeese rate me , i am desperate :o)))