File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes JTable Multi Column Sort selected row not correct Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTable Multi Column Sort selected row not correct " Watch "JTable Multi Column Sort selected row not correct " New topic
Author

JTable Multi Column Sort selected row not correct

Jay Brass
Ranch Hand

Joined: Oct 24, 2000
Posts: 76
Hey There,

I have a JTable in a JScrollPane. The table model is created from a resultset from a database query. I've set tempTable.setRowSorter(sorter) where sorter is a new TableRowSorter<TableModel>(model); I've also set sorter.setMaxSortKeys(4); because I only want to sort on 4 specific columns. Currently I call a header render to sort the columns but after it sorts them the selected row is incorrect. I had to add the columns to the SortKeys and adjust for the column selected to sort on so that it would be similar to an OrderBy clause in a database query. Does anyone have any idea how to keep the selected column after the sort? Converting to model or view don't seem to help.
From the class where the table is:


the table header render class
Jay Brass
Ranch Hand

Joined: Oct 24, 2000
Posts: 76
I realized that my rowListener and my tableHeaderRender were in both trying to update the selected row. I created a RowClickedListener that extended MouseAdapter to check for when a user clicked on a row instead of when they clicked on a header. Long story short, this allowed me to set a boolean value and only change (or reset) the selected row to what the user clicked on and not what the header sort had changed it to. Seems to work pretty well.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JTable Multi Column Sort selected row not correct
 
Similar Threads
create a jtable which can combine and split and the image change also
Table Row Selection problem while adding any Image in a JTable
ListSelectionListener and double clicks
ListSelectionListener getting cell value and assigning it to a variable
Images in a JTable