• 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 row change event?

 
Ranch Hand
Posts: 41
Hibernate Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I'm displaying database rows in a JTable and wan't to detect when a user selects a different row in the list of rows. The default behaviour is that you can highlight different rows but I don't know what event to listen for or how. Any ideas? My aim is to display fields from the highlighted row in form input types so the user can update them. Thanks

Samson.
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use a TableModelListener that you attach to the JTable's model. There is only one event (tableChanged) so you should check the TableModelEvent's type.
 
Rancher
Posts: 3324
32
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
See: How to Write a List Selection Listener
 
Rob Spoor
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rob C is actually right. TableModelListener is for noticing changes in the data (model). A ListSelectionListener is for noticing selection changes.

That article is missing a part though. It only describes how to handle selections of entire rows. If you change the table to allow selection of single cells then you must not only add a ListSelectionListener to the JTable's ListSelectionModel, but also to the ListSelectionModel of the JTable's TableColumnModel.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic