Solved

Some more help with JRadioButtons in a JTable

Posted on 2006-07-19
12
346 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
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 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
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 …
Suggested Courses

732 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