• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Apply JTable Cell Editor for a specific row/column.

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic