aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes different JComboBoxes as editors on multiple JTable rows Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "different JComboBoxes as editors on multiple JTable rows" Watch "different JComboBoxes as editors on multiple JTable rows" New topic
Author

different JComboBoxes as editors on multiple JTable rows

Matthew Taylor
Rancher

Joined: Jun 13, 2004
Posts: 110
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 ]

Grails Consultant
http://dangertree.net
Matthew Taylor
Rancher

Joined: Jun 13, 2004
Posts: 110
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: different JComboBoxes as editors on multiple JTable rows