⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 e421. listening for changes to preference values in a preference node.txt

📁 这里面包含了一百多个JAVA源文件
💻 TXT
字号:
A PreferenceChangeEvent is fired when a preference is added, changed, or removed from a preference node. This event is only guaranteed to fire if the listener and modifier are in the same application. This event is not fired if the node is removed. 
See also e422 Determining When a Preference Node Is Added or Removed. 

    // Retrieve the user preference node for the package java.lang
    Preferences prefs = Preferences.userNodeForPackage(String.class);
    
    // Register the listener
    prefs.addPreferenceChangeListener(new PreferenceChangeListener() {
        public void preferenceChange(PreferenceChangeEvent evt) {
            // Get the node that changed
            Preferences node = evt.getNode();
    
            // Get the affected key.
            // Note: it is not possible to tell if the key was new
            // or its value was changed.
            String key = evt.getKey();
    
            // Get the new value; if the new value is null,
            // the preference was removed
            String newValue = evt.getNewValue();
        }
    });
    
    // Add a preference
    prefs.put("key", "a string");
    
    // Modify the preference
    prefs.put("key", "a new string");
    
    // Remove the preference
    prefs.remove("key");

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -