This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting data from JTable

 
Dilip kumar
Ranch Hand
Posts: 360
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I would like to retrieve all the values when a particular row is selected in JTable. Which method should I use ? I�m using Model � View � Controller to populate data in JTable.
Thanks
 
deekasha gunwant
Ranch Hand
Posts: 396
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Dilip,
In case you are using DefaultTableModel.then u can use the following
DefaultTableModel dm = tableName.getModel();
Vector data = dm.getDataVector();
getDataVector() returns the table data in a vector form.
regards
deeksha



 
Dilip kumar
Ranch Hand
Posts: 360
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Deekasha,
One more question.
How to identify the row # selected ?
Thanks
 
deekasha gunwant
Ranch Hand
Posts: 396
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

You can use getSelectedRow()/getSelectedRows() method of JTable class.
this method returns the row index(es) of the selected row(s).
regards
deeksha


 
Hemal Joseph
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to retrieve values From JTable and set them into database again.
I am creating a JTable by fetching values which are present in database and then allowing user to modify them.
Now how to know that the row or the column has been changed, and if changed, then how to set them back into database.
Please guide me.
Hemal.
------------------
 
Hemal Joseph
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by deekasha gunwant:
[B]hi,

You can use getSelectedRow()/getSelectedRows() method of JTable class.How to retrieve values From JTable and set them into database again.
I am creating a JTable by fetching values which are present in database and then allowing user to modify them.
Now how to know that the row or the column has been changed, and if changed, then how to set them back into database.
Please guide me.
Hemal.
 
Swamy Vatti
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hemal,
for every row you should have a flag(false). and update this flag(true) in the setValueAt method.
So when you save(ie click a button to save), just take out the rows which have this flag true;
Similarly if you want to go cell level, then you should be having a flag for each cell. I guess there is no other work around direct from the API.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic