When a table is in sorting mode (using RowSorter
), it seems that most of time the table is sorted in realtime. For example, whenever I add new rows, the table is sorted automatically (except editing cell). I am wondering if there is any way to disable this realtime sorting behaviour.
What I want to do is this: After sorting a table, either ascending or descending, then the sorter keeps the current sort state and stops realtime sorting. Then new rows can be added at the bottom, and selected row can be move up and down, and the table updates all changes in view model.
@trashgod: thanks for your answer. I actually kind like native rowsorter method, as I can circle the column state in tri-state (ascending, descending and unsorted). If using Collections.sort, I will have to create a variable to save the original row order before sorting it everytime.
You can order the rows of your
TableModel
independent ofRowSorter
usingCollections.sort()
and a customComparator
, such as the one shown here, that can accept a parameter specifying the sort direction.