Retrieving the Color Chooser Panels in a JColorChooser Dialog
import javax.swing.JColorChooser;
import javax.swing.colorchooser.AbstractColorChooserPanel;
public class Main {
public static void main(String[] argv) {
JColorChooser chooser = new JColorChooser();
findPanel(chooser, "javax.swing.colorchooser.DefaultSwatchChooserPanel");
findPanel(chooser, "javax.swing.colorchooser.DefaultHSBChooserPanel");
findPanel(chooser, "javax.swing.colorchooser.DefaultRGBChooserPanel");
}
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;
}
}
Related examples in the same category