• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Taking controll over sorting in JTable

 
Christian Kindler
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,

I want to use JTable's standard sorting mechanism with TableRowSorter which works fine. But I want to have the control about when sorting is done. Sorting is triggered by JTable if the TableModel what is not what I want. I want to occur sorting only if the user clicks on the table header and by explicitly calling the sort method. Is there any way to achieve this?

Regards,
Christian
 
mark goking
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
did you try calling the jTable.setRowSorter() in the table header's event method when it is clicked?

 
Christian Kindler
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
mark goking wrote:did you try calling the jTable.setRowSorter() in the table header's event method when it is clicked?


The problem with installing/removing the row sorter as needed is, that the table will restore the unsorted state when the RowSorter is removed.
 
Mikko Kohtamäki
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well I only checked that JTable notifies rowSorter if table's sortManager is != 'null' through tableChanged method, and this may work.. If you dont want table to sort every time the model changes...

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic