Event listeners can be removed again from any Properties
node, but the instance of the listener has to be kept around for that.
Preferences preferences = Preferences.userNodeForPackage(getClass());
PreferenceChangeListener listener = evt -> {
System.out.println(evt.getKey() + " got new value " + evt.getNewValue());
};
preferences.addPreferenceChangeListener(listener);
//
// later...
//
preferences.removePreferenceChangeListener(listener);
Preferences preferences = Preferences.userNodeForPackage(getClass());
PreferenceChangeListener listener = new PreferenceChangeListener() {
@Override
public void preferenceChange(PreferenceChangeEvent evt) {
System.out.println(evt.getKey() + " got new value " + evt.getNewValue());
}
};
preferences.addPreferenceChangeListener(listener);
//
// later...
//
preferences.removePreferenceChangeListener(listener);
The same applies for NodeChangeListener
.