Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Jtable loading after being saved problem

 
Mostafa Ahmad
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thaaaaaaaaaaaaaaaaaaaaaaanks very much, your hint solved the problem.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic