Changing JTableModel does not change JScrollpane size
I basically want to let the user filter data within a table and change row colors accordingly.
The data for my table is held within the table model.
Table rows should be colored white or gray. Looking only at a certain column, if the cell's value of the current row is incremented by 1 compared to the previous one the color should switch. I seem to have accomplished this by overriding the prepareRenderer method.
However, the user can decide to filter rows in the table. I have also managed to use a filter for the table that works. However, after filtering, rows color should be rerendered since some rows could be omitted and the policy of one row's color depending on the previous still holds.
This does not happen. Rows retain the color previously assigned to them before filtering.
I read on the net that cell rendering happens only once, when the table is first painted. Therefore, I a filter does NOT invoke the table to rerender it is understandable that rows would retain their color.
Therefore, I tried changing the data itself in the data model and use fireTableDataChanged() so that the entire table would get rerendered.
Well that doesn't solve the problem.
Although the table gets updated, the jscrollpane within which it is placed gets partially updated. If the table gets shortened the top of the table gets updated but the scroll bar does not and when I scroll down I see lines that are not supposed to be there and the table freezes.
I tried using revalidate() and repaint() for the scrollpane as well for its parent but nothing works.
table = new JTable(tableModel);
scrollPane = new JScrollPane();