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.
The Java Preference API is the way to go.
You can find an overview here.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With