I have a JTable with a custom TableModel that extends AbstractTableModel. I also used the built-in table sort by calling:
table.setAutoCreateRowSorter(true);
The model also returns the correct data class for each column from the getColumnClass () call, which from what I read should provide the fastest sorting.
While it works fine and a really really fast sorting method in JTables, it is exceptionally slow when the number of rows reaches 5000+ records. My nearly 10,000 row table now takes 6-7 seconds to sort on a fairly powerful computer. But if I sort the data myself before adding it to the model using the collection sorting algorithm, this is done in a few milliseconds!
I suspect that the built-in sorter fires a lot of unnecessary events for each "swap" of elements that go into the sorter algorithm, even if the repainting is stopped before it finishes (the built-in sorter obviously works in the AWT stream and, therefore, blocks the entire GUI / repainting). I did not analyze this by looking at what actually happens in the sorting of the table.
I am tempted to abandon the entire built-in sorter and simply detect clicks on the column header and just sort the model myself before doing fireTableDataChanged (), which was what the built-in sorter should do.
But before I do this, I don’t notice what the built-in sorter can make fast?