• Post Reply Bookmark Topic Watch Topic
  • New Topic

JTable fireTableChanged() calling clearSelection()?  RSS feed

 
Richard Harris
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm working on an application where an asynchronous process is populating a JTable. However, the user can pre-select a row on the table. (Long story)
I store the row number for the pre-selected table, and I've defined a listener that will select the row when the table has been populated and does a fireTableChanged().
What I'm seeing, however, is that after it runs the listener code, it seems to call clearSelection(), so it is selecting and then immediately clearing all selections.
I guess I have two questions:
1. Am I right? Is this really what fireTableChanged() does?
2. How do I work around this so I automatically select a row after the table data is changed?
Thanks,
- Rick
 
Richard Harris
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Never mind. I think I figured it out. JTable also implements TableModelListener. When the data changes it calls the tableChanged() method in JTable, which, as of 1.3, clears any selections on the JTable.
If you extend JTable and override tableChanged() to first call the parent functionality and then re-select, that should do it.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!