Search code examples
javaswingjtabletablecellrendererjtableheader

JTable - Sorting rendered values column


In JTable, all the columns can be sorted by using Table.setAutoCreateRowSorter(true); method. But the sorting is not properly in one column in that table which contains cell renderer. If you have any idea about it, please reply.


Solution

  • If you use a custom renderer to display the data then you also need to create a custom Comparator to sort the data in that column.

    Read the section from the Swing tutorial on Sorting and Filtering for an example of a Comparator that you can set on the TableRowSorter.