Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

different JComboBoxes as editors on multiple JTable rows

 
Matthew Taylor
Rancher
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Objective: Use JComboBoxes within two columns of a JTable. Within each row of the table, the value of the first JComboBox will dictate what values are presented for selection within the second JComboBox.

Problem: I can't find a good way to specify a different cell editor for each row within a column. It's easy to choose an editor for the entire column, but in this case I may want to use different JComboBox options on different rows.

Sample Code: This code doesn't attempt to solve the entire problem, but shows the problem I'm running into right now. I have a debugging statement that writes out a message to the screen each time an ActionEvent occurs on a JComboBox within the first column. I'm trying to assign a unique ID to each JComboBox within each row so I can tell which one was chosen. That way I can tell which corresponding JComboBox in the second column to manipulate in response. However, every time an event is fired from the event-dispatching thread during execution, the same JComboBox is the source (it happens to always be the last one that was created).


This is just the last attempt I've made at this problem. I've been working on it sporatically for about a week. Please help if you have any experience with this.

[ June 20, 2005: Message edited by: Peter Glass ]
[ June 20, 2005: Message edited by: Peter Glass ]
 
Matthew Taylor
Rancher
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nevermind, I figured it out. The only way I could add a different renderer and editor for my table was to extend JTable and overwrite the getCellEditor(int row, int col) and getCellRender(int row, int col) methods.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic