Java examples for Native OS:Preference
Determining When a Preference Node Is Added or Removed
import java.util.prefs.BackingStoreException; import java.util.prefs.NodeChangeEvent; import java.util.prefs.NodeChangeListener; import java.util.prefs.Preferences; public class Main { public void main(String[] argv) { Preferences prefs = Preferences.userNodeForPackage(String.class); prefs.addNodeChangeListener(new NodeChangeListener() { public void childAdded(NodeChangeEvent evt) { Preferences parent = evt.getParent(); Preferences child = evt.getChild(); }/*from w ww . ja v a 2 s.c o m*/ public void childRemoved(NodeChangeEvent evt) { Preferences parent = evt.getParent(); Preferences child = evt.getChild(); } }); Preferences child = prefs.node("new node"); try { child.removeNode(); prefs.removeNode(); } catch (BackingStoreException e) { } } }