This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread 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 Android Security Essentials Live Lessons this week in the Android 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...

 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Taking controll over sorting in JTable
 
Similar Threads
JTable header click event ?
JTable
JTable
JTable
JTable ........