How to sort a JTable when it is created

529 Views Asked by At

Say I have a table that the first column is id, and I want the table to be sorted by id number when it is created. What can I do?

I hope 'sorting before the construction of the table' is not the only solution.

1

There are 1 best solutions below

1
On BEST ANSWER

Try this code

JTable table = new JTable();
table.setAutoCreateRowSorter(true);
table.getRowSorter().toggleSortOrder(0);