alexander-r
3/15/2020 - 4:18 PM

JTable sort on multiple columns

TableRowSorter<TableModel> sorter = new TableRowSorter<>(table.getModel());
table.setRowSorter(sorter);
List<RowSorter.SortKey> sortKeys = new ArrayList<>();
 
int columnIndexForJob = 2;
sortKeys.add(new RowSorter.SortKey(columnIndexForJob, SortOrder.ASCENDING));
 
int columnIndexForName = 1;
sortKeys.add(new RowSorter.SortKey(columnIndexForName, SortOrder.ASCENDING));
 
sorter.setSortKeys(sortKeys);
sorter.sort();