Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Apply JTable Cell Editor for a specific row/column.  RSS feed

 
Stephen Wells
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have constructed a Property Sheet using a JTable. The property sheet is 2 columns Name and Value. The some values in the property sheet are editable. In one instance the value in a specific row/column can be one of a list of values a great place for a ComboBox. I have seen lots of examples of setting a ComboBox editor for all the cells in a column but how do I apply a cell editor to a specific cell at row 5, column 1? Or is there a better way than using a Cell Editor?

Thanks
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JTable has a method "public TableCellEditor getCellEditor(int row, int column)" which returns the actual TableCellEditor to use. (There is a sibling for TableCellRenderer as well.) By overriding that and returning something else you can actually determine for each cell separately which renderer / editor to return. Keep in mind though that those row and column numbers are from the JTable's point of view; use convertRowIndexToModel and convertColumnIndexToModel to get the row and column numbers from the TableModel's point of view.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!