As the title states, I have a JTable
and I am unable to edit "arbitrary" columns. I have 4 columns and only the first column is editable. The first column has files and a special editor, the next two columns have Strings, and the last column has Integers. I'm using a custom model, and I am returning true from the isCellEditable
method. Of course, I consulted several websites for help first, but I was unable to find anything that helped. I used the java source code to override several JTable
methods and insert print statements. In particular, I found that table.editCellAt(row, col) always returns false because the editing component returned from the cell editor is always null. So, I naturally tried to replace the editor using table.setDefaultEditor(String.class, new MyEditor())
. Oddly, that DID NOT work. All editors for the String columns were still the GenericEditor that JTable uses by default. I then tried adding the Editors to each column by doing the following:
TableColumnModel model = table.getColumnModel();
for(int i = 1; i < model.getColumnCount(); i++){
model.getColumn(i).setCellEditor(new MyEditor());
}
Note that i starts at 1 because the first column already has an appropriate editor. I'm out of ideas at this point so I came to the good people at Stack Overflow for some help.
Edit:I am using a DefaultTableModel
, I simply overrode isCellEditable
to make sure it always returns true (even though DefaultTableModel
is supposed to do that be default). I did this to reduce the amount of unhelpful, wasteful debugging responses. Also, the fact that one column is editable but others aren't would seem to indicate the problem is elsewhere.
Edit: It would appear the issue rested with column creation. A professor suggested changing setAutoCreateColumnsFromModel
and it seems to have fixed the issue.