Some more help with JRadioButtons in a JTable

Seems I closed this question prematurely:
http://www.experts-exchange.com/Programming/Programming_Languages/Java/Q_21921480.html

Basically, I have that working as it should, Except for the fact that I can't seem to figure out which JRadioButton is actually selected... I have only two radiobuttons, andI'm trying to determine whether the first one is selected:

I have tried both:
tblData.getCellEditor(i,
                        tblData.getColumn("Type").getModelIndex()).
                        getCellEditorValue().toString().equals("0");

model.getValueAt(i, tblData.getColumn("Type").getModelIndex()).
                        toString().equals("0");
LVL 9
riaancorneliusAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
objectsConnect With a Mentor Commented:
have your next button call stopCellEditing()
0
 
Tomas Helgi JohannssonCommented:
   Hi!

Take a look at this example http://www.java2s.com/Code/Java/Swing-JFC/RadioButtonDemo.htm
Hope it helps.

Regards,
  Tomas Helgi
0
 
girionisCommented:
Hi TomasHelgi

why don't you simply have a reference to the RadioButtonPanel in your class and then get this reference? Something like the following:

RadioButtonPanel panel = new RadioButtonPanel(answer);
table.getColumn("Answer").setCellEditor(new RadioButtonEditor(panel));

public RadioButtonPanel getPanel()
{
   return panel;
}

Cheers
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
girionisCommented:
Then if you have the panel you can work out wihich jradiobuttons are selected.
0
 
riaancorneliusAuthor Commented:
Hi Girionis, The problem is that I need a different panel for each row, Don't I? I'm getting really confused about what is actually happening in this JTable.

Can somebody please explain in laymen terms what happens in the example I used in the above mentioned question?
0
 
objectsCommented:
why exactly do you need to know which radio button is selected?

> Can somebody please explain in laymen terms what happens in the example I used in the above mentioned question?

when the row is editted the column is 'replaced' with the panel allowing the user to select a radio button.
0
 
girionisCommented:
riaancornelius,
>  Don't I?

Not sure. I think the RadioButtonPanel takes the whole column.
0
 
riaancorneliusAuthor Commented:
>> why exactly do you need to know which radio button is selected?
I have a table with a choice between two options. After the user makes the selection for each row and hits the next button, I need to know which option was selected for each row, so that I can process each row differently based on the option.

The way I understand it, this editor will change the underlying Integer columns value to the radiobuttons index that is selected, so that if I call table.getValueAt(row,col) it should return index of the radioButton?
0
 
objectsCommented:
thats right, so is getValueAt() returning the correct value?
0
 
riaancorneliusAuthor Commented:
Guys, getValueAt() returns the right value, but that value is only updated once the cell loses focus.

In my app I was editing the cell, and then clicking on the next button, so the cell didn't lose fucus, and hence the value wasn't updated.
0
 
riaancorneliusAuthor Commented:
So now the question is, How do I get the cellEditor to update the value the moment you click on a Radiobutton?
0
 
riaancorneliusAuthor Commented:
thanks objects :)
0
All Courses

From novice to tech pro — start learning today.