Hi ranchers I have swing screen with JTable of user's list and additional information besides the table that changes on each row selection. This data is additional user data that doesn't fit the table.
When the moving from one row to another I am collecting all additional row data to map and I attach it as hidden filed to the JTable model. Finally when the screen is submitted, all data is flushed to the db.
My question is how I listen to the "row lost focus" and "row got focus" event in order to initiate the additional data according to the selected row, and save the data when moving to the next row
But Brian, won't that only show you the selected row(s)? I think Sharon needs the row that lost focus. I am assuming she just needs to keep track of that herself? For example, once the first row becomes selected, save that as a selected row in some other data structure. When the next row is selected, find the last selected row in the data structure before adding the newly selected row. Then she would know when row was deselected?
Originally posted by Gregg Bolinger: But Brian, won't that only show you the selected row(s)? I think Sharon needs the row that lost focus. I am assuming she just needs to keep track of that herself?
Pretty much yes. You can actually query the ListSelectionEvent for the range of rows that may have changed [via e.getFirstIndex() and e.getLastIndex()] and can ask the table [via yourTable.isRowSelected() or other ways] if each row in the range is selected. Depending on your needs you can sometimes treat the selected rows in the range as new selections and unselected rows in the range as new deselections, but it's certainly possible that some of the rows in the middle of the range have not changed selection state. To get things perfect you have to keep track of the rows yourself somehow. If you're going to be doing this a lot you may want to create a custom subclass of DefaultListSelectionModel.
[edit: custom subclass of DefaultListSelectionModel, not ListSelectionModel since that's an interface] [ January 01, 2008: Message edited by: Brian Cole ]
Joined: Jul 31, 2003
Originally posted by Brian Cole:
[edit: custom subclass of DefaultListSelectionModel, not ListSelectionModel since that's an interface]