Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Column-Sort JTable

AykutNov 12 2017 — edited Nov 13 2017

How can I sort for example the 4th column of a JTable ?

The following code does not work:

TableRowSorter<TableModel> sorter = new TableRowSorter<>(jTable.getModel());

jTable.setRowSorter(sorter);

List<RowSorter.SortKey> sortKeys = new ArrayList<>();

int columnIndex = 4;

sortKeys.add(new RowSorter.SortKey(columnIndex, SortOrder.ASCENDING));

sorter.setSortKeys(sortKeys);

sorter.sort();

Jtable shows always the unsorted table.

I also tried with other columns. No sorting.

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 11 2017
Added on Nov 12 2017
1 comment
882 views