Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to "un-sort" a JTable?

I created a TableRowSorter for a JTable, and I was able to sort the table correctly. But is there a way to get the table back to its original state before I sorted it? I tried clicking on the table header, but it seems that it only sorts the table in ascending or descending order, and it doesn't return the table back to its original state prior to the sort. Is it possible to un-sort the table and get it back to its original state? Thanks!

like image 792
BJ Dela Cruz Avatar asked Feb 21 '23 11:02

BJ Dela Cruz


1 Answers

Empty sortKeys list indicates the view should be unsorted. Try the following to restore original row order:

table.getRowSorter().setSortKeys(null);

Read more in RowSorter spec.

like image 90
tenorsax Avatar answered Apr 01 '23 12:04

tenorsax