Ordering Jtable Elements Using a Specific Column - JAVA

Trying to arrange the jtable with the "Days of the week" column, because the names of the days of the week are not ordered as soon as they appear on the jtable. Beans binding was used to bind the database (MYSQL) to jtable, but I need an event to sort the entries by the column of the day of the week (Mon, W .... in that order).

+3
source share
2 answers

There are different types of sortable JTables, and you can have a comparator for each column if you want. Samples can be found in java2s , and you can also consider SwingX , where you can also specify your own comparator.

+1
source

RowSorter JTable, , .

, :

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

Source: https://habr.com/ru/post/1788426/


All Articles