![]() |
The Java Developers Almanac 1.4 |
|
e880. Retrieving the Color Chooser Panels in a JColorChooser DialogThere are three chooser panels in the defaultJColorChooser
dialog. Although each is implemented by a class in the
javax.swing.colorchooser package, these classes are not public.
This example demonstrates how to identify these panels by class name.
JColorChooser chooser = new JColorChooser();
// Retrieve the swatch chooser
findPanel(chooser, "javax.swing.colorchooser.DefaultSwatchChooserPanel");
// Retrieve the HSB chooser
findPanel(chooser, "javax.swing.colorchooser.DefaultHSBChooserPanel");
// Retrieve the RGB chooser
findPanel(chooser, "javax.swing.colorchooser.DefaultRGBChooserPanel");
// Returns the panel instance with the specified name.
// Returns null if not found.
public AbstractColorChooserPanel findPanel(JColorChooser chooser, String name) {
AbstractColorChooserPanel[] panels = chooser.getChooserPanels();
for (int i=0; i<panels.length; i++) {
String clsName = panels[i].getClass().getName();
if (clsName.equals(name)) {
return panels[i];
}
}
return null;
}
e882. Setting the Order of the Color Chooser Panel Tabs in a JColorChooser Dialog e883. Adding a Custom Color Chooser Panel to a JColorChooser Dialog
© 2002 Addison-Wesley. |