Reputation: 131
JTable
Header1 | Header2 | Header3
temp1 | temp1 | Boolean.FALSE
temp2 | temp2 | Boolean.TRUE
temp3 | temp3 | Boolean.FALSE
temp4 | temp4 | Boolean.TRUE
How can I sort Header3? into Boolean.TRUE first then Boolean.FALSE.
Upvotes: 0
Views: 127
Reputation: 205875
I don't know to set the third column as the one to be sorted.
Referring to the tutorial and this example, you can specify the column and SortOrder
like this for CHECK_COL
:
public CheckABunch() {
...
table.setAutoCreateRowSorter(true);
DefaultRowSorter<DefaultTableModel, Integer> sorter =
((DefaultRowSorter) table.getRowSorter());
List<RowSorter.SortKey> sortKeys = new ArrayList<RowSorter.SortKey>();
sortKeys.add(new RowSorter.SortKey(CHECK_COL, SortOrder.DESCENDING));
sorter.setSortKeys(sortKeys);
}
Upvotes: 2
Reputation: 823
You can use TableRowSorter for sorting. Search for it, you will get plenty of examples.
Upvotes: 0