I need to modify any given column's header in my JTable. I couldn't
find a way of doing this, so I attempted to remove the necessary
TableColumn and re-add a TableColumn into the same position. The
problem I'm having is that it adds the TableColumn to the end of the
JTable, even when I set the appropriate index in the TableColumn
constructor. I've tried adding the TableColumn to the JTable and its
DefaultTableModel, neither works.
Here is the code I'm using:
TableColumn newCol = new TableColumn(index);
newCol.setHeaderValue(new String("New"));
TableColumn oldCol =
tblDecisionMatrix.getColumnModel().getColumn(index );
//tblDecisionMatrix.removeColumn(oldCol);
//tblDecisionMatrix.addColumn(newCol);
TableColumnModel colMdl = tblDecisionMatrix.getColumnModel();
colMdl.removeColumn(oldCol);
colMdl.addColumn(newCol);
Any help would be much appreciated. Please email replies to
td***@perfectsolve.com
Thanks,
Tamir