• 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: How to keep selected row visible after sort?

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'd like to keep the selected row visible whenever a JTable is sorted. I've tried to fix it in a RowSorterListener, but it seems like the listener is called BEFORE the table is sorted (table.getSelectedRow() returns the row which was selected before the sort). The attached example will hopefully show what I mean. If I select a row and then sort the table by clicking one of the column headers, the selected row will most likely disappear out of view.

Any suggestions?

Thanks.

 
Rancher
Posts: 3324
32
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not a very good example since the data in the model keep changing...

Anyway, I think the problem is that the data has actually been sorted when the RowSorterEvent is fired. So try wrapping the code in an invokelater to add your selection code to the end of the EDT so that the scrollRectToVisible() is done after the sorting is finished.

 
Bottolf Knotten
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic