aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Getting data from JTable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Getting data from JTable" Watch "Getting data from JTable" New topic
Author

Getting data from JTable

Dilip kumar
Ranch Hand

Joined: Oct 16, 2000
Posts: 360
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

Joined: May 06, 2000
Posts: 396
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

Joined: Oct 16, 2000
Posts: 360
Deekasha,
One more question.
How to identify the row # selected ?
Thanks
deekasha gunwant
Ranch Hand

Joined: May 06, 2000
Posts: 396
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

Joined: Jul 20, 2001
Posts: 3
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

Joined: Jul 20, 2001
Posts: 3
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

Joined: May 02, 2001
Posts: 57
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.


Swamy
 
Don't get me started about those stupid light bulbs.
 
subject: Getting data from JTable