• Post Reply Bookmark Topic Watch Topic
  • New Topic

Saving a Panel  RSS feed

 
Gayathri Neti
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a very interesting Question for you guys. I want to save the JPanel along with its contents to the disk and open it when ever need. It�s like saving the form in VB and opening the form. But in my case it is a JPanel. I used a JFileChooser to obtain a open and save dialog box. Any help in this regard is greatly appreciated.

Gayathri Neti.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think that there is anyway to really save the JPanel itself, say similar to an image or however you had invisioned it.
What I would do is save the attributes of the JPanel to a text file. Similar to this.
jpanel.dat
[constraints]
x=100
y=100
[components]
.
.
.
.
Anyway, you get the idea. Basically, save a dat file that contains all the properties of the JPanel and then when you need to draw than JPanel again, access that dat file to find out how to draw it.
Make sense?
Hope so.
 
Gayathri Neti
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hai,
What you suggested make sense to me, but there are 9 buttons and 3 labels and the contents of all these Items keep changing. So how can I get the text on the labels and the labels content itself............Is there any way.
Thanks,
Gayathri
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are get..() methods for all components so you will be able to get what you need when it is time to save. Take a look at the API for each component and it will show you all the methods you need.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!