riaancornelius
asked on
Some more help with JRadioButtons in a JTable
Seems I closed this question prematurely:
https://www.experts-exchange.com/questions/21921480/JRadioButtons-in-a-JTable.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"). getModelIn dex()).
getCellEditorValue().toStr ing().equa ls("0");
model.getValueAt(i, tblData.getColumn("Type"). getModelIn dex()).
toString().equals("0");
https://www.experts-exchange.com/questions/21921480/JRadioButtons-in-a-JTable.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").
getCellEditorValue().toStr
model.getValueAt(i, tblData.getColumn("Type").
toString().equals("0");
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"). setCellEdi tor(new RadioButtonEditor(panel));
public RadioButtonPanel getPanel()
{
return panel;
}
Cheers
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").
public RadioButtonPanel getPanel()
{
return panel;
}
Cheers
Then if you have the panel you can work out wihich jradiobuttons are selected.
ASKER
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?
Can somebody please explain in laymen terms what happens in the example I used in the above mentioned question?
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.
> 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.
riaancornelius,
> Don't I?
Not sure. I think the RadioButtonPanel takes the whole column.
> Don't I?
Not sure. I think the RadioButtonPanel takes the whole column.
ASKER
>> 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?
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?
thats right, so is getValueAt() returning the correct value?
ASKER
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.
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.
ASKER
So now the question is, How do I get the cellEditor to update the value the moment you click on a Radiobutton?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks objects :)
Take a look at this example http://www.java2s.com/Code/Java/Swing-JFC/RadioButtonDemo.htm
Hope it helps.
Regards,
Tomas Helgi