your renderer never sets the selected item, thus it will always be the default
Set the required value in getTableCellRendererCompon
Main Topics
Browse All TopicsI'm stuck. I have a JTable that holds a JComboBox which is populated depending on the value in another cell (plain) in the same row. Everything displays correctly, with the correct values in each combo box. The problem is when I make a selection on a combo box, any previous combo box selections revert to the default state. I know I'm stomping on either my combo box instance or the Vector I'm populating it with in either my cell editor or cell renderer class. I'm also fairly certain I'm implementing too many instances of JComboBox.
Thanks in advance....
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
In getTableCellRendererCompon
if(value == null){
comboBox = new JComboBox();
}else{
Vector vector = (value instanceof Vector)?(Vector)value:new Vector();
comboBox = new JComboBox(vector);
}
}
so should I change that to :
int x = the seleceted index; //dig this value out of the ItemEvent?
new JComboBox(vector.elementAt
?
I thought maybe my problem is that in my table, I'm sending the renderer the Vector associated with the row I've clicked on, so it overwrites what was populating the comboBox in the previously selected row?
So I made this change:
public Vector getValuesVector(int row, int column){
Object[] modelRow = tableModel.getData()[row];
return new Vector((Vector)modelRow[co
}
///////
MyComboBoxRenderer renderer = new MyComboBoxRenderer( getValuesVector(int row, int column));
But the values are different in the new Vector(which is the only value the renderer knows),so the selected item doesn't exist the next time the renderer gets called, right?
So, how do I fix THAT?
That's what I figured.
One idea I have is to create a data structure that I populate with my result set data and then iterate through it and create a new JComboBox for each set, and just pass them into my renderer and editor.
Or, just use the data structure to hold reference to each collection for the comboBoxes.
Yeah they're all different, because the value in the other column (which comes from another -simpler- query) is a parameter in the query that produces the values for the combo. By the nature of the schema, they all come out with different value sets. Of course, we're talking 1 - n combos with 0-n items in each one.
I'm still trying to come up with a way to persist the different value sets, but it's tough when it's unkonwn how many there might be.
As I think about it, maybe some factory could pop out the vectors that would all be unique instances, but for the renderer to hold reference to the right one is a challenge.
I'm sure the project architect thought this looked real cool when he did it in vizio.
Business Accounts
Answer for Membership
by: jolly_rogPosted on 2008-06-18 at 15:15:56ID: 21817794
Just to clarify, the value in the other column is a parameter for a sql query, hence the different values for each row's comboBox. It's also persisted in the data object retrieved from the tableModel, but the value is irrelevant to the current problem.