The Java Developers Almanac 1.4


Order this book from Amazon.

   
Home > List of Packages > javax.swing.colorchooser  [10 examples] > Color Chooser Panel  [4 examples]

e880. Retrieving the Color Chooser Panels in a JColorChooser Dialog

There are three chooser panels in the default JColorChooser 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;
    }

 Related Examples
e881. Removing a Color Chooser Panel from a JColorChooser Dialog
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

See also: Events    Preview Panel   


© 2002 Addison-Wesley.