For that purposes you can use TableRowSorter
, and set Comparator
to needed column. In that comparator you can compare values of cells and sorting them:
TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(model);
sorter.setComparator(0, new Comparator<Object>() {
@Override
public int compare(Object o1, Object o2) {
return 0;
}
});
table.setRowSorter(sorter);
table
is your JTable
, model
is model of your table.
read more about sorting in JTable
.