Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Keep selected row highlighted after table model changes

 
Robert McDonald
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Just trying to refine my gui (and not very familiar with Swing) and i was wondering if there was a way to keep the selected row highlight after the fireTableDataChanged() has occured. To explain a bit, a user selects a row and books the room - currently i refresh the data and set the results in the table model and fire the table changed event. This refreshes the Jtable but removes the highlight of the selected row. I thought it would be good to keep this highlighted to help the user see which record has been updated.

Hope this makes sense(!) and that someone might know a (simple!) way of doing this...

Robert
 
B Chen
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could 'remember' the record number of the record you modified and select that row when you redisplay the records.
 
Robert McDonald
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi B,

Thanks for replying. I was recording the selected rowno (in a listener) and trying to reselect but because i fireTableDataChanged (within the table model records setter) this was notifying the listener and changing the selected row no back to -1. I could have stored a 'previousselected rowno' which wasn't tied to the listener but in the end came up with a better solution (I think).

I took the fireTableDataChanged out of the table model code and just call that on the table model when necessary (i.e. after a search or show all records). When i refresh the data after a book i just call fireTableRowsUpdated(selectedRowNo, selectedRowNo) which just updates this row.

I think this is a better solution for me and in the end provides more flexibily.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic