![]() |
The Java Developers Almanac 1.4Order this book from Amazon. |
e871. Setting a UI Default Value That Is Created When FetchedWhen 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. TheUIDefaults 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 // 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");
e872. Setting a UI Default Value That Is Created at Every Fetch © 2002 Addison-Wesley. |