Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

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.
 
A sonic boom would certainly ruin a giant souffle. But this tiny ad would protect it:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic