Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Persistent state for Java UI elements between runs

I have a Java program which has a number options it allows the user to change, mostly via JComboBox. The only problem is that every time the user closes the program the settings reset, because they are not actually stored anywhere. Is there a standard way to give Java programs persistent state between runs? I could write the settings to a temporary file, but it seems like there should be a more elegant solution.

like image 515
Altay_H Avatar asked May 02 '11 17:05

Altay_H


2 Answers

The Java Preference API is the way to go.
You can find an overview here.

like image 137
Romain Hippeau Avatar answered Oct 02 '22 08:10

Romain Hippeau


If you keep your entire application Javabean-safe, and extend the standard JFrame classes such and such, you should be able to serialise the entire object graph to file and reload it.

See Restore previously serialized JFrame-object, how? for more details.

like image 36
Chris Dennett Avatar answered Oct 02 '22 08:10

Chris Dennett