• Post Reply Bookmark Topic Watch Topic
  • New Topic

Saving and loading data of a Jtable  RSS feed

 
Dominic Omari
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey I'm pretty new to this forum, and to Java itself.
I am trying to make a program where a user can enter guests name for a hotel, the JTable includes rows for the name of the tenant, the room number, month etc.
I've made the table, however I am having some trouble in saving the data that I put into the table. I used jtextfield and a jbutton to but data into the jtable. I am trring to save the data, and load it just buy clicking a button.
This is my basic table.

And what I'm trying to do to save the data is:

When I run my program, I'm able to click on a button, and the dialog box will appear, I'm also able to save the data to a file. However when I click on the retieve data button I made the dialog box opens, the file is there, however when I click it, nothing happens.
Any help will be much appreciated.
Thanks
 
Rob Camick
Ranch Hand
Posts: 2787
12
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


When you save the data you are saving a DefaultTableModel.



When you read the data you are trying to read in a Vector? Why a Vector, you saved a DefaultTableModel? You can't just randomly change the type of data in the saved object.

So read in a DefaultTableModel. Once you read the model you need to add the model to the table:

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!