is there anyway to invoke the auto row sorter in a jtable that is created by using
setAutoCreateRowSorter(true);
i'm trying to get it to sort by a default column without the user having to click on on the column header.
We can sort a JTable in a particular column by using the method setAutoCreateRowSorter() and set to true of JTable class.
An implementation of RowSorter that provides sorting and filtering using a TableModel . The following example shows adding sorting to a JTable : TableModel myModel = createMyTableModel(); JTable table = new JTable(myModel); table. setRowSorter(new TableRowSorter(myModel));
table.getRowSorter().toggleSortOrder(modelColumnIndex)
TableRowSorter rowSorter = (TableRowSorter) table.getRowSorter();
List<SortKey> keys = new ArrayList<SortKey>();
SortKey sortKey = new SortKey(2, SortOrder.ASCENDING);//column index 2
keys.add(sortKey);
rowSorter.setSortKeys(keys);
rowSorter.sort();
i'm trying to get it to sort by a default column without the user having to click on on the column header.
I think you have to use setSortsOnUpdates(true) method from TableRowSorter class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With