This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Swing / AWT / SWT and the fly likes Taking controll over sorting in JTable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Taking controll over sorting in JTable" Watch "Taking controll over sorting in JTable" New topic
Author

Taking controll over sorting in JTable

Christian Kindler
Greenhorn

Joined: Apr 16, 2009
Posts: 18
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

Joined: Aug 18, 2009
Posts: 155
did you try calling the jTable.setRowSorter() in the table header's event method when it is clicked?


Website/Java Games: http://www.chitgoks.com
Tech Blog: http://tech.chitgoks.com
Christian Kindler
Greenhorn

Joined: Apr 16, 2009
Posts: 18
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

Joined: Dec 13, 2008
Posts: 112
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...

 
jQuery in Action, 2nd edition
 
subject: Taking controll over sorting in JTable