• 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 ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

JTable TableCellRenderer based on row, col value help

Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've been trying different things for awhile now only to end up at the same place. I've searched the interwebs and still can't find a good solution to my problem:

I have a jTable with 5 columns set up in the following way
0 1 2 3 4
| # | type | Table Name | Field Name | Value |

I have 2 types {Variable, SMDB} if variable is selected, col 2 (Table Name) is set to a JComboBox with the tables only Variable types can access. Once a table Name has been chosen from col 2; col 3 is set to a combo box with the fields only available from the selected table.

as you can see I can't implement a columnmodel type cell editor beucase the editor is row/col independent because there's mutable rows all having different type/table name/field name combinations.
I've been playing around with overriding getValueAt(int row, int col) to check the previous col and return the combobox but I can't seem to render it. The cell will just have a string representation of the object.
I've also tried custom cell renderers but I can't seem to get it right.

Can anyone help?

some info if needed:
tableNames are in a linked hashmap where the key is the tablename and the value is a hashset of fieldNames

this table is displayed once someone clicks on a "rule" from a JTree. The "rule" will have data to put into the JTable that will work with the previously stated combo boxes.
This data is editable -- the comboboxes come into play.
The user can add new rows -- the comboboxes are again used.

if anyone could offer some insight, links, code, etc. it would be awesome. I'm fairly certain this isn't impossible...it might be extremely easy, actually. I just can't see it :[
Posts: 22784
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
You can override "public TableCellRenderer getCellRenderer(int row, int column)" and "public TableCellEditor getCellEditor(int row, int column)" to return a custom cell renderer / editor based on the cell, not just the column. I used that to be able to display a different renderer per cell myself, like a check box for Booleans, images for Image / ImageIcon, etc. And all in the same column.
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic