Java: Possible to replace TableModel in an existing JTable?
Asked Answered
A

2

7

Is it possible to replace the entire TableModel in an existing JTable or do I have to recreate the JTable?

Amphoteric answered 30/5, 2011 at 16:36 Comment(0)
K
15

You can set a new model using the JTable.setModel() method

Check the Javadocs for details

Knickers answered 30/5, 2011 at 16:38 Comment(2)
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.Amphoteric
Very helpful in the case of a JXTreeTable as well, where you might have to use setTreeTableModel().Lethargic
S
5

When you change the model you are stuck with old column titles. getColumnName() only gets called on initialization.

Sloshy answered 21/5, 2013 at 15:1 Comment(1)
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!Plenty

© 2022 - 2024 — McMap. All rights reserved.