Reputation: 33
Trying to order a jtable by the Days of week column since the day of week names are not in order once they are displayed on the jtable. Beans binding has been used to link database(MYSQL) with the jtable, but i need an event to sort the entries by the day of week column (Mon, Tues....in this order).
Upvotes: 3
Views: 1535
Reputation: 324147
You can add a RowSorter to the JTable and the user can click on any heading to do a sort.
If you want to presort the data then you can manually do a sort:
table.setAutoCreateRowSorter(true);
DefaultRowSorter sorter = ((DefaultRowSorter)table.getRowSorter());
ArrayList list = new ArrayList();
list.add( new RowSorter.SortKey(2, SortOrder.ASCENDING) );
sorter.setSortKeys(list);
sorter.sort();
Upvotes: 1