Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JTable loses selection  RSS feed

 
Pete Mosca
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a large amount of data to display in a JTable.
I am loading the data into the model on a separate thread so that the list may be used while data is still being added to the list.
My problem is that when I select a row on the table, that selection is cleared when I add new elements to the model.
What would cause the selection to be cleared?
 
Stefan Freyr
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's causing it is that the underlying data model changed.

It doesn't matter that you're just adding to the end of the rows, the JTable doesn't know that. You could just as well have completely changed the TableModel, rearranged the rows or even have different columns. In such a case re-selecting the previous indices would be rather silly.

So what you need to do is store the selected indices in an int array, register a change listener to the table and reapply the selected indices on the table when you receive a table changed event.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!