Java Reference
In-Depth Information
•
public UIDefaults.ProxyLazyValue(String className, Object[] arguments)
: If object
creation will use a constructor that requires some arguments, pass the class name and
array of arguments to the
ProxyLazyValue
constructor.
•
public UIDefaults.ProxyLazyValue(String className, String method, Object[]
arguments)
: If object creation will use a factory method that does require arguments,
pass the factory method name along with the class name and array of arguments.
For the lazy diamond icon implementation that's about to be created, you'll need to pass
state information that consists of the color, selected state, and dimensions.
To test the lazy diamond icon, you can associate an instance of
UIDefaults.ProxyLazyValue
to
the
Tree.openIcon
setting, as follows:
Integer fifteen = new Integer(15);
Object lazyArgs[] = new Object[] { Color.GREEN, Boolean.TRUE, fifteen, fifteen} ;
Object lazyDiamond = new UIDefaults.ProxyLazyValue("DiamondIcon", lazyArgs);
UIManager.put("Tree.openIcon", lazyDiamond);
Together with the previous change of the
Tree.leafIcon
setting to the
World.gif
icon, and
using the default tree data model, the tree would look like Figure 20-4.
Figure 20-4.
A tree created with lazy values
Listing 20-4 shows the source code for the example that generated Figure 20-4 by using the
two lazy values.
Listing 20-4.
Lazy UIResources
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.plaf.*;
public class LazySample {
public static void main (String args[]) {
Runnable runner = new Runnable() {
public void run() {
JFrame frame = new JFrame("Lazy Example");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);