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.

有帮助吗?

解决方案

Try this code

JTable table = new JTable();
table.setAutoCreateRowSorter(true);
table.getRowSorter().toggleSortOrder(0);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top