I implemented row sorting in JTable using DefaultRowSorter and my own row sorter class. Everything works fine by clicking on the column heading to sort the table.
But what about if I want to call a sort operation from my application code (without clicking on the column heading). What method do I need to call?
EDIT:
I initialize the table row sorter as follows:
public void buildRowSorter() { TableRowSorter<MyModel> sorter = new TableRowSorter<MyModel>((MyModel)this.table.getModel()); try { sorter.setComparator(0, new MyCustomComparator<Double>(sorter,0)); sorter.setComparator(1, new MyCustomComparator<String>(sorter,1)); } catch (ParseException e) { e.printStackTrace(); } this.table.setRowSorter(sorter); }
Now I would like, having a link to JTable (table), to get the associated row sorter into a specific column of my model and invoke a sort operation on it.
source share