• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JTable Multi Column Sort selected row not correct

 
Ranch Hand
Posts: 76
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 76
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic