Is it possible to invoke the auto row sorter in a jtable
Asked Answered
A

3

7

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.

Argentum answered 26/10, 2011 at 14:7 Comment(0)
A
20
table.getRowSorter().toggleSortOrder(modelColumnIndex)
Amphistylar answered 26/10, 2011 at 14:25 Comment(0)
L
8
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();
Lamoree answered 26/10, 2011 at 14:26 Comment(2)
curious: setSortKeys is documented to trigger a sort (if the given list is different than the current), no explicit sort() needed - or have you found corner cases where it was?Amphistylar
I haven't had problems before. I just didn't read the API correctly and always added the sort :(Lamoree
A
2

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.

Attitudinize answered 26/10, 2011 at 14:21 Comment(1)
that's not an answer to the question as I understand it, could be me mis-understanding, though :-)Amphistylar

© 2022 - 2024 — McMap. All rights reserved.