Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Some more help with JRadioButtons in a JTable

Posted on 2006-07-19
12
Medium Priority
?
349 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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
 
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 2000 total points
ID: 17137047
have your next button call stopCellEditing()
0
 
LVL 9

Author Comment

by:riaancornelius
ID: 17137296
thanks objects :)
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Suggested Courses

610 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