There are two types of events emitted by a Preferences
object: PreferenceChangeEvent
and NodeChangeEvent
.
A PreferenceChangeEvent
gets emitted by a Properties
object every time one of the node's key-value-pairs changes. PreferenceChangeEvent
s can be listened for with a PreferenceChangeListener
:
preferences.addPreferenceChangeListener(evt -> {
String newValue = evt.getNewValue();
String changedPreferenceKey = evt.getKey();
Preferences changedNode = evt.getNode();
});
preferences.addPreferenceChangeListener(new PreferenceChangeListener() {
@Override
public void preferenceChange(PreferenceChangeEvent evt) {
String newValue = evt.getNewValue();
String changedPreferenceKey = evt.getKey();
Preferences changedNode = evt.getNode();
}
});
This listener will not listen to changed key-value pairs of child nodes.
This event will be fired whenever a child node of a Properties
node is added or removed.
preferences.addNodeChangeListener(new NodeChangeListener() {
@Override
public void childAdded(NodeChangeEvent evt) {
Preferences addedChild = evt.getChild();
Preferences parentOfAddedChild = evt.getParent();
}
@Override
public void childRemoved(NodeChangeEvent evt) {
Preferences removedChild = evt.getChild();
Preferences parentOfRemovedChild = evt.getParent();
}
});