• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

saving the contents of a JTable

 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 91
IntelliJ IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 . . .
 
Ranch Hand
Posts: 119
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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().
 
brevity is the soul of wit - shakepeare. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic