user979490
user979490

Reputation: 280

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

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.

Upvotes: 7

Views: 8845

Answers (3)

camickr
camickr

Reputation: 324118

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();

Upvotes: 8

kleopatra
kleopatra

Reputation: 51525

table.getRowSorter().toggleSortOrder(modelColumnIndex)

Upvotes: 20

Eng.Fouad
Eng.Fouad

Reputation: 117597

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.

Upvotes: 2

Related Questions