• Post Reply Bookmark Topic Watch Topic
  • New Topic

Saving Table Model data

 
Daniel Roach
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17290
9
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Swati Gupta
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!