my dog learned polymorphism
The moose likes Swing / AWT / SWT and the fly likes Saving Table Model data Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Reply Bookmark "Saving Table Model data" Watch "Saving Table Model data" New topic
Author

Saving Table Model data

Daniel Roach
Greenhorn

Joined: Mar 12, 2002
Posts: 10
I have a 'spreadsheet' like application in which the user selects a file, using JFileChooser, which is passed to the constructor of a class extending abstract table model. This file is read and then used to populate a Jtable which is then displayed in an internal frame. The user can change the values in the table, and I need to be able to save these changes. I have a save file menu item, which chooses a file to save, but from this method I am unable to access the ArrayLists which hold the data in the table model. I wanted to convert these into strings and then save the file. Does anyone have any ideas to solve this, I know there must be an easy answer.
Thanks in advance
Dan
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17243
    
    1

Extend the DefualtTableModel class into your own TableModel, then you can override the getValueAt, and other get methods that will return only what you want it to, and in the class/format you want, then you can just pass this returned class to your "Save" method and viola. Of course the exact implementation of this, I will leave to you to do.
Here is the link to the TableModel Tutorial Page. You will find some good info here.
Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Swati Gupta
Ranch Hand

Joined: May 28, 2002
Posts: 106
I have done the similar work.
I am using a Vector to get the data from the file.
Also I am using a AbstractTableModel and defining all the methods my own.
When user changes any cell of the table I shows a Diaalog to confirm the changes and later using a Mwnu user can save the changes.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Saving Table Model data
 
Similar Threads
Client data
MVC modify model from outside of the table.
JTable question
JTable
JDialog return value