Lost CellRenderer when updating TableModel
I am working on some code, where I need to modify the displayed columns in a table.
The table consists of cells that uses a custom CellRenderer implemented by the class MonitorCellRenderer.
So far I have some of the functionality working in that I can make the table display less columns. This is achieved by modifying the data stored in the TableModel. In fact what I do is re-create the Column Headers and data.
This is all achieved by firing a fireTableStructureChanged() event. Then I recompose the data in the Table Model. I call JTable.setModel() with the Table Model reference again, and the table is re-structured. BUT....
The cell rendering does not work, all that is displayed is the object reference for the data (The data for each cell is stored in an object). This is the same as would have happened if I had not initialised a CellRenderer for the table, so I implemented the following code in my TableModelListener
for(int col = 0; col < monitorTable.getModel().getColumnCount(); col++)
{
column = monitorTable.getColumnModel().getColumn(col);
column.setCellRenderer(new MonitorCellRenderer());
column.setPreferredWidth(100);
column.setResizable(false);
}
monitorTable is the JTable. This code is cribbed from the inital set up for the table, so is essentially what I want. What I have found is that these settings for the column are ignored, because if I change the preferred width, it does not change.
I'm thinking that somehow my table ColumnModel reference is wrong, because it is referencing something else.
Can anyone suggest what may be going wrong.
Thanks

