I would like to use combo boxes in my tables but have different values
in combo boxes that are in the same column. If found the following
example on the java website:
TableColumn sportColumn = table.getColumnModel().getColumn(2);
...
JComboBox comboBox = new JComboBox();
comboBox.addItem("Snowboarding");
comboBox.addItem("Rowing");
comboBox.addItem("Chasing toddlers");
comboBox.addItem("Speed reading");
comboBox.addItem("Teaching high school");
comboBox.addItem("None");
sportColumn.setCellEditor(new DefaultCellEditor(comboBox));
But this example only allows the same combo box for every row. How can
I fix this?
Thanks,
Adam
Rhino - 02 Jun 2006 23:08 GMT
>I would like to use combo boxes in my tables but have different values
> in combo boxes that are in the same column. If found the following
[quoted text clipped - 13 lines]
> But this example only allows the same combo box for every row. How can
> I fix this?
"Fix" suggests "broken" and I don't think this is broken; the concept
behind columns in a JTable are that each of values in the column are of the
same type and subject to the same renderers and editors. I'd be surprised if
you could set a different editor on different cells of the same column; that
would appear to defy the basic reasoning behind the JTable.
But I could be wrong. The best article I've ever seen on renderers and
editors is at
http://www-128.ibm.com/developerworks/library/j-jtable/. Maybe if you read
that you will get an idea on how to do what you want to do - or a
categorical statement that it can't be done at all. I haven't been through
the article in a fair while so I don't remember all the details of what the
author says.
--
Rhino
Christian Kaufhold - 04 Jun 2006 12:01 GMT
> I would like to use combo boxes in my tables but have different values
> in combo boxes that are in the same column. If found the following
> example on the java website:
> But this example only allows the same combo box for every row. How can
> I fix this?
Use a custom cell editor, which has different editorComponents for different
rows.