This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Jtable loading after being saved problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Jtable loading after being saved problem" Watch "Jtable loading after being saved problem" New topic
Author

Jtable loading after being saved problem

Mostafa Ahmad
Greenhorn

Joined: Feb 22, 2011
Posts: 11
Hello Everyone

I am making an application that has a jtable that I want to save or load.

I am saving JTable as an object in a file ,and saving is done properly, but the problem is in loading. There is no error or exception while loading, but nothing changes in the showed Jtable.

loading button action performed is :



Saving button action performed is :




Can anyone tell me what should I do ?
Paul Clapham
Sheriff

Joined: Oct 14, 2005
Posts: 19728
    
  10

When you read the data back from the file, you change the "Table" variable so it now refers to some other JTable than the one which is displayed in the GUI. That of course doesn't change the GUI in any way.

The way to fix that is to not save the JTable. There isn't any point in saving the GUI component, anyway. What you really want to save is the data, which is the contents of the TableModel. To save the data, get the TableModel from the JTable and write that to the file. To restore the data, read the TableModel back from the file and put it into the JTable via the JTable's setModel() method.
Mostafa Ahmad
Greenhorn

Joined: Feb 22, 2011
Posts: 11
Thaaaaaaaaaaaaaaaaaaaaaaanks very much, your hint solved the problem.
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: Jtable loading after being saved problem
 
It's not a secret anymore!