I have a JTable with about 17 columns. For some of these columns I want ComboBoxes, for others, I don't. Some code:
public final JTable table;
void setCellEditors(){
setBooleanCellEditor (table); // comboBox for boolean values
setIntCellEditor (table); // comboBox for int values
setTypeCellEditor (table);
setAnotherTypeCellEditor (table);
// .. and so on, for all types I need comboboxes
}
The cellEditor function for most types look like this:
private void setTypeCellEditor (JTable jt) {
DefaultCellEditor dce = new DefaultCellEditor (Type.buildComboBox ());
jt.setDefaultEditor (Type.class, dce);
}
And this works fine, because that type is unique for that table, in other words, I only have one column with type Boolean, one with Int, one with AnotherType etc. The problem now is that two columns have String values, but need different ComboBoxes. Meaning, the code above doesn't work, because they are both String.class.
Naturally, I tried solving this by saying "On column 10 I want this ComboBox":
private void setYetAnotherTypeCellEditor (JTable jt) {
DefaultCellEditor dce = new DefaultCellEditor (YetAnotherType.buildComboBox ());
if (jt.getColumnModel ().getColumnCount() > 0) {
jt.getColumnModel ().getColumn (9).setCellEditor (dce);
}
}
This, however, doesn't seem to work and I do not know why. I also tried this guide but that doesn't help. Basically, I think setCellEditor isn't setting the cell editor for some reason.
It is difficult to be more specific because there is a lot of code behind this.