Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import javax.swing.JColorChooser;
import javax.swing.colorchooser.AbstractColorChooserPanel;

public class Main {
    public static void main(String[] argv) {
        JColorChooser chooser = new JColorChooser();
        int numPanels = chooser.getChooserPanels().length;
        AbstractColorChooserPanel[] newPanels = new AbstractColorChooserPanel[numPanels];
        newPanels[0] = findPanel(chooser, "javax.swing.colorchooser.DefaultHSBChooserPanel");
        newPanels[1] = findPanel(chooser, "javax.swing.colorchooser.DefaultRGBChooserPanel");
        newPanels[2] = findPanel(chooser, "javax.swing.colorchooser.DefaultSwatchChooserPanel");
        chooser.setChooserPanels(newPanels);
    }

    public static 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;
    }
}