Tutorial by Examples

There are two types of events emitted by a Preferences object: PreferenceChangeEvent and NodeChangeEvent. PreferenceChangeEvent A PreferenceChangeEvent gets emitted by a Properties object every time one of the node's key-value-pairs changes. PreferenceChangeEvents can be listened for with a Prefer...
Preferences objects always represent a specific node in a whole Preferences tree, kind of like this: /userRoot ├── com │   └── mycompany │   └── myapp │   ├── darkApplicationMode=true │   ├── showExitConfirmation=false │   └── windowMaximized=true └── org └...
All instances of Preferences are always thread-safe across the threads of a single Java Virtual Machine (JVM). Because Preferences can be shared across multiple JVMs, there are special methods that deal with synchronizing changes across virtual machines. If you have an application which is supposed...
Preferences nodes can be exported into a XML document representing that node. The resulting XML tree can be imported again. The resulting XML document will remember whether it was exported from the user or system Preferences. To export a single node, but not its child nodes: Java SE 7 try (Output...
Preferences nodes can be imported from a XML document. Importing is meant to be used in conjunction with the exporting functionality of Preferences, since it creates the correct corresponding XML documents. The XML documents will remember whether they were exported from the user or system Preferenc...
Event listeners can be removed again from any Properties node, but the instance of the listener has to be kept around for that. Java SE 8 Preferences preferences = Preferences.userNodeForPackage(getClass()); PreferenceChangeListener listener = evt -> { System.out.println(evt.getKey() + ...
A value of a Preferences node can be of the type String, boolean, byte[], double, float, int or long. All invocations must provide a default value, in case the specified value is not present in the Preferences node. Preferences preferences = Preferences.userNodeForPackage(getClass()); String som...
To store a value into the Preferences node, one of the putXXX() methods is used. A value of a Preferences node can be of the type String, boolean, byte[], double, float, int or long. Preferences preferences = Preferences.userNodeForPackage(getClass()); preferences.put("someKey", "...
Preferences can be used to store user settings that reflect a user's personal application settings, e.g. their editor font, whether they prefer the application to be started in full-screen mode, whether they checked a "don't show this again" checkbox and things like that. public class Exi...

Page 1 of 1