Forum Stats

  • 3,817,472 Users
  • 2,259,339 Discussions
  • 7,893,790 Comments

Discussions

Column-Sort JTable

Aykut
Aykut Member Posts: 53
edited Nov 13, 2017 11:37AM in Swing

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.

Answers

This discussion has been closed.