JTableHeader not refreshing
Hello,
I'm implementing a table that allows a person to right click on cells and either delete the entire rows or columns that have been selected. I have no problems modifying the tablemodel to delete the rows or columns, but I can't seem to get the JTableHeader to remove the deleted column names... I made sure to delete the column names in my table model as well. I also tried calling the 'columnRemoved' method on the tableheader to no avail. Here's a sample of my action listener and my removeColumns call in my table model. Does anyone know if I'm missing something? I also tried a revalidate(), repaint(), but no luck.
ActionListener
Code:
public void actionPerformed(ActionEvent ae)
{
Object eventSource = ae.getSource();
if (eventSource==_deleteColumnMenuItem)
{
JScrollPane scrollPane = (JScrollPane) _tabbedDataPane.getSelectedComponent();
JTable table = (JTable) scrollPane.getViewport().getView();
UniqueTableModel tableModel = (UniqueTableModel) table.getModel();
TableColumnModel columnModel = table.getColumnModel();
int[] selectedColumnIndices = columnModel.getSelectedColumns();
tableModel.removeColumns(selectedColumnIndices);
TableColumnModelEvent columnModelEvent = new TableColumnModelEvent(columnModel, selectedColumnIndices[0], selectedColumnIndices[selectedColumnIndices.length-1]);
table.getTableHeader().columnRemoved(columnModelEvent);
}
}
removeColumns
Code:
public void removeColumns(int[] columnIndices)
{
Arrays.sort(columnIndices);
for (int index=columnIndices.length-1; index >=0; index--)
{
// remove column name
_columnNames.remove(columnIndices[index]);
// iterate through each row and remove the specified column
for (List<Object> row : _rowHashedData)
{
row.remove(columnIndices[index]);
}
}
fireTableDataChanged();
}