Is it possible to replace the entire TableModel in an existing JTable or do I have to recreate the JTable?
Asked
Active
Viewed 1.1k times
2 Answers
15
You can set a new model using the JTable.setModel()
method
Check the Javadocs for details
-
Damn - I was using the inline javadoc in the eclipse editor and I missed it, but I went back and checked and it's there. – opike May 30 '11 at 16:45
-
Very helpful in the case of a JXTreeTable as well, where you might have to use `setTreeTableModel()`. – Stéphane Bruckert Apr 09 '15 at 09:35
5
When you change the model you are stuck with old column titles. getColumnName()
only gets called on initialization.
-
so it is not possible to change the column names as well? In my case, I want to make a data viewer table, it gets initialized without data and filled once a different thread provides the model. But, as you said, column names are not appearing! – A. Harkous Jul 13 '18 at 08:29