Updating number of columns in TableModel
i use a DataModel which extends an AbstractTableModel for my Jtable.
When i use the constructor JTable main = new JTable(model);
everything works fine but when i add columns to my DataModel and call this.fireTableStructureChanged()
the number of columns does not update as can be seen in the following example.
It shows a JTable initialised with my DataModel, which contained 3 rows and 3 columns. The DataModel has been updated to 4 rows and 4 columns but does only show 3 colu开发者_如何学Cmns.
My Changeevent seems to be wrong because:
JTable.getColumnCount() shows 3
but DataModel.getColumnCount() shows 4
How can i tell the Table that the number of columns has changed and it should repaint them?
The JTable also has a TableColumnModel which holds all the columns to show. When you add another column to your model, the column model still has the old number of columns unless the table's autoCreateColumnsFromModel
property is set to true (table.setAutoCreateColumnsFromModel(true)
).
The other way would be to manually add another column to the column model.
精彩评论