• Post Reply Bookmark Topic Watch Topic
  • New Topic

saving the contents of a JTable  RSS feed

 
Scott A Burch
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How would one store the contents of a JTable? I am working up a JTable of seven columns and up to fifteen rows, all of which are designed for user input. I have inserted a "save" button in the interface and the idea would be that once a user session is done, the user would click "save" so the contents will be preserved for the next launch of the app.The first column is a string, the next three are Date objects, and the next three are boolean check boxes. Any suggestions?
 
Vineeth Menon
Ranch Hand
Posts: 79
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Scott,

When you are using JTable, your table data should be managed by using a TableModel like the AbstractTableModel. It's quite hard to explain how to use the TableModel, but I guess you can refer to examples provided by Java on JavaDocs which I guess you might have checked. You can also refer to this site JTableImplementationExample . Hope this helps . . .
 
Wayan Saryada
Ranch Hand
Posts: 119
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And how are you going to make this data persistent? Storing into a file on the disk or do you want to save it in a database? Each will of course need a different way to code it.
 
Scott A Burch
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I looked at the sample code and did not see the mechanism that will take the values of the table and let me store for recall later. Where is it? The app I am writing uses an AbstractTableModel.

The data will be stored as a file of some sort on an internal hard drive; storing the table's values into a database seems like overkill considering the purpose of this application. I envision not more than 24 rows of activity in the application. FileWriter / FileReader, perhaps?
 
Scott A Burch
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I may have googled up my own answer. See [url=https://forums.oracle.com/forums/thread.jspa?threadID=1288644]
 
Wayan Saryada
Ranch Hand
Posts: 119
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Basically you can read JTable's TableModel using the getModel() method. You can then read the value from the TableModel using the getValue(row, column) method. This method will return the value for each row, column index in the table. The number of row and column can be read using getRowCount() and getColumnCount().
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!