File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 Spring in Action this week in the Spring 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
Bartender

Joined: Oct 14, 2005
Posts: 18656
    
    8

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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Jtable loading after being saved problem