📄 e871. setting a ui default value that is created when fetched.txt
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -