• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

How to use ListSelectionListener in Jtable?

 
Ranch Hand
Posts: 34
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
Can anyone tell me, how to use ListSelectionListener in jtable to get row values and store it an database?
 
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
I'm not sure I understand the question.

It seems like you want to get the values of a selected row and copy them to a database. If this is the case then you would not want to use a ListSelectionListener. This event fires every time you click on a row or use the arrow keys to move up/down in the table.

Instead I would suggest you need a button like "Update Database". Then you can use the table.getSelectedRows() method to get the index of all selected rows. Then you can loop through the array and access the data in each row by using the getValueAt(...) method for each row and for every column in the row.

But if you really want to use a ListSelectionListener then you can read the Section from the Swing tutorial on How to Write a List Selection Listener for an example.
 
vignesh karthick
Ranch Hand
Posts: 34
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Mr.Rob Camick. This is the exact solution that i need.
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic