Java Reference
In-Depth Information
frame.setSize(300, 100);
frame.setVisible(true);
}
};
EventQueue.invokeLater(runner);
}
}
Using the ColorChooserComponentFactory Class
One class worthy of some special attention is ColorChooserComponentFactory . Normally, this
class does its work behind the scenes, and you never need to deal with it.
However, if you want to remove one of the default color choosers, you cannot use the
public AbstractColorChooserPanel removeChooserPanel(AbstractColorChooserPanel panel)
method of JColorChooser . Initially, the chooserPanels property of JColorChooser is null . When
this property is null , the default ColorChooserUI asks the ColorChooserComponentFactory for the
default panels with the public static AbstractColorChooserPanel[ ] getDefaultChooserPanels()
method. So, until you modify the property, no panels will appear. If you want to remove a
default panel, you must get the default array, place the panels you want to keep in a new array,
and then change the chooserPanels property of the chooser to the new array. This is a little
extra work, but it gets the job done.
The other method in the ColorChooserComponentFactory class is public static JComponent
getPreviewPanel() , which gets the default preview panel when the previewPanel property of a
JColorChooser is null . This is the reason that providing a null argument to the setPreviewPanel()
method of JColorChooser doesn't remove the preview panel. For the panel to be empty, you
must provide a JComponent with no size.
colorChooser.setPreviewPanel(new JPanel());
Customizing a JColorChooser Look and Feel
The JColorChooser appearance is nearly the same for all the preinstalled look and feel types.
The only differences are related to how each look and feel displays the internal components,
such as a JTabbedPane , JLabel , JButton , or JSlider . Changing the UIResource -related properties
of those components affects the appearance of a newly created JColorChooser . In addition, the
JColorChooser class has its own 39 UIResource -related properties available for customization,
as listed in Table 9-9. Most of these resources are related to text labels appearing on the various
default color chooser panels.
Table 9-9. JColorChooser UIResource Elements
Property String
Object Type
ColorChooser.background
Color
ColorChooser.cancelText
String
ColorChooser.font
Font
ColorChooser.foreground
Color
Search WWH ::




Custom Search