tags:

views:

59

answers:

4

Hi I have written a small java program based on swing application. Now I want to store the object of my swing application (jframe) in database and I want to retrieve the same from database when its necessary. during retrieve i want to get the same object. I am using sqlite as database

How to achieve this functionality

Thanks Sunil Kumar Sahoo

A: 

I don't know about sqlite, but Preferences is a a good way to store information about your JFrame.

Catalina Island
+1  A: 

Are you sure you want to store the view and not the Model? Another method except for Preferences is to use XMLEncoder

Romain Hippeau
I want to store both
Deepak
@Sunil Kumar Sahoo Why do you want to store both ?
Romain Hippeau
A: 

To my knowledge it's not actually possible to save the JFrame to a database. Whether you do it yourself or with some kind of library the way it works is that you save to the db all the information you need to recreate your JFrame.

Kempeth
A: 

A JFrame implements Serializable so theoretically it is serializable as an ObjectStream you could use ObjectInputStream and ObjectOutputStream and write the stream to the database.

All components in the JFrame should also be serializable. However it is not really advised to do this since the api says "Serialized objects of this class will not be compatible with future Swing releases."

Redlab