I have a JTable and a TableRowSorter which I’d like to perform an operation after a sort is finished. I’ve been browsing the net, and so far I haven’t had much luck.
Initially I thought just a RowSorterListener would do the trick, but unfortunately it doesn’t perform the operation after the sort is finished.
Adding a MouseListener to the JTable header could work, but the solution isn’t terribly elegant.
Does anyone have any ideas?
Thanks a bunch!
Edit (from comment): The following is added in a method inside a custom TableModel class which extends AbstractTableModel. This method is invoked whenever the JTable is set/specified in the custom TableModel class.
sorter.addRowSorterListener(new RowSorterListener() {
@Override public void sorterChanged(RowSorterEvent rowsorterevent) {
rebuildMItems(); // The method which executes
}
});
Two possibilities:
I see you have a custom
RowSorter. Couldn’t you simply add a call to your operation at the end of thesort()method?In other words, can you add this:
to your sorter?
Your current method (doing it in a
RowSorterListener) performs the operation twice: once forSORT_ORDER_CHANGEDand once forSORTED. Can you check the event’s type and only perform the operation at the correct time?