TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(tblProduct.getModel());
tblProduct.setRowSorter(sorter);
List<RowSorter.SortKey> sortKeys = new ArrayList<>();
sortKeys.add(new RowSorter.SortKey(6, SortOrder.DESCENDING));
sorter.setSortKeys(sortKeys);
It is sorting it in order by the first number of the integer rather than the whole number, what is the easiest way of fixing this?
i.e. output like:
9
8
8
5
2
17
12
1
String
and notInteger
– g00seJTables
. I would guess you either need to change the model for the sort column to Integer like g00se intimated, or find a way to alter the comparator (if possible) to convert the String to an Integer for sorting purposes. – WJSgetColumnClass(...)
method of the model to tell the table what the class of each column of data contains. See: stackoverflow.com/questions/34026013/… – camickr