e872. setting a ui default value that is created at every fetch.txt

来自「这里面包含了一百多个JAVA源文件」· 文本 代码 · 共 23 行

TXT
23
字号
The UIDefaults table supports values that are created every time they are fetched. Such values are called active values. 
For values that are created only once, see e871 Setting a UI Default Value That Is Created When Fetched. 

This example declares an active value (a Date) that is created every time it is fetched. 

    // Create an active value
    Object activeValue = new UIDefaults.ActiveValue() {
        // This method is called every time the value is fetched.
        // If this method can be called no more than once, it must be synchronized.
        public Object createValue(UIDefaults table) {
            return new Date();
        }
    };
    
    // Add the active value to the UI defaults table
    UIManager.put("key", activeValue);
    
    // Fetch the value twice; this causes the value to be created twice
    Date d1 = (Date)UIManager.get("key");
    Date d2 = (Date)UIManager.get("key");
    boolean b = d1.equals(d2);   // false

⌨️ 快捷键说明

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