e871. setting a ui default value that is created when fetched.txt
来自「这里面包含了一百多个JAVA源文件」· 文本 代码 · 共 24 行
TXT
24 行
When a UI default value is fairly large and may never be used, the value should be lazily created. This means that the value should be created only when the value is fetched. The UIDefaults table allows for such values.
For values that are created every time they are fetched, see e872 Setting a UI Default Value That Is Created at Every Fetch.
This example declares a lazy value (a JPanel) that is created only when fetched.
// Create a lazy value
Object lazyValue = new UIDefaults.LazyValue() {
// This method is called once, when the value is fetched.
// If this method can be called no more than once, it must be synchronized.
public Object createValue(UIDefaults table) {
// The returned value will be permanently stored in the UI default table
return new JPanel();
}
};
// Add the lazy value to the UI defaults table
UIManager.put("key", lazyValue);
// Fetch the value; this causes the value to be created
Object value = UIManager.get("key");
Related Examples
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?