When using a custom RowSorter (or any RowSorter for that matter), one must take care to make sure the models of the sorter and the table always match. As specified in the setRowSorter
Javadoc:
If the underlying model of the RowSorter differs from that of this JTable undefined behavior will result.
The setModel
method of the JTable will not update the row sorter, unless you are using a default automatic one (by setting the autoCreateRowSorter
flag).
As such, you should
- keep a reference to your sorter and update its model as well
OR - use the default row sorter by setting
setAutoCreateRowSorter(true)
on your table and not a custom one,