Solved

Some more help with JRadioButtons in a JTable

Posted on 2006-07-19
12
342 Views
Last Modified: 2008-03-06
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");
0
Comment
Question by:riaancornelius
  • 5
  • 3
  • 3
  • +1
12 Comments
 
LVL 25

Expert Comment

by:Tomas Helgi Johannsson
ID: 17136705
   Hi!

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

Regards,
  Tomas Helgi
0
 
LVL 35

Expert Comment

by:girionis
ID: 17136743
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
 
LVL 35

Expert Comment

by:girionis
ID: 17136745
Then if you have the panel you can work out wihich jradiobuttons are selected.
0
 
LVL 9

Author Comment

by:riaancornelius
ID: 17136765
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
 
LVL 92

Expert Comment

by:objects
ID: 17136815
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
 
LVL 35

Expert Comment

by:girionis
ID: 17136822
riaancornelius,
>  Don't I?

Not sure. I think the RadioButtonPanel takes the whole column.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 9

Author Comment

by:riaancornelius
ID: 17136910
>> 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
 
LVL 92

Expert Comment

by:objects
ID: 17136918
thats right, so is getValueAt() returning the correct value?
0
 
LVL 9

Author Comment

by:riaancornelius
ID: 17137004
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
 
LVL 9

Author Comment

by:riaancornelius
ID: 17137044
So now the question is, How do I get the cellEditor to update the value the moment you click on a Radiobutton?
0
 
LVL 92

Accepted Solution

by:
objects earned 500 total points
ID: 17137047
have your next button call stopCellEditing()
0
 
LVL 9

Author Comment

by:riaancornelius
ID: 17137296
thanks objects :)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Unable to start eclipse ? 17 134
AWS and Java and Rest - newbie question (Is this an authentication issue) 4 68
xampp tool 12 30
Oracle SQL syntax check  without executing 6 38
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

27 Experts available now in Live!

Get 1:1 Help Now