• 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 � handle Row lost focus event

 
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

Thank you
Sharon
 
Author
Posts: 986
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Sharon whipple:
JTable ...
My question is how I listen to the "row lost focus" and "row got focus" event



The typical way is something like this:

 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Brian Cole
Author
Posts: 986
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 ]
 
Sharon whipple
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Brian Cole:

[edit: custom subclass of DefaultListSelectionModel, not ListSelectionModel since that's an interface]




I DefaultListSelectionModel and I'm saving the last row when the selection is changed.

Working great!!
Thank you
Sharon
 
reply
    Bookmark Topic Watch Topic
  • New Topic