e880. retrieving the color chooser panels in a jcolorchooser dialog.txt

来自「这里面包含了一百多个JAVA源文件」· 文本 代码 · 共 29 行

TXT
29
字号
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;
    }


⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?