views:

59

answers:

2

I have this JTable on my Swing app with the autoCreateRowSorter enabled. My table only has 3 columns, two strings and one int, it works well for all of them when I click the column headers.

However, I'm looking for way to do it programatically. I wanted to set the "initial state" for this table. With the Windows look and feel, the column header (when sorted) has a little arrow showing the sort order. But at startup that doesn't show, I have to do one initial click.

How can I do that by code?

+1  A: 

To programaticallly sort the table you can do something like:

DefaultRowSorter sorter = ((DefaultRowSorter)table.getRowSorter());
ArrayList list = new ArrayList();
list.add( new RowSorter.SortKey(0, SortOrder.ASCENDING) );
sorter.setSortKeys(list);
sorter.sort();
camickr
So many lines for such a simple thing, I hate Java lol. Thanks :)
Nazgulled
A: 

I think DefaultRowSorter#toggleSortOrder(int column) will do the work

barjak