There will come a time when you want only a selected tab to appear in the JColorChooser. As far as I know, there is no way to do this with Java‘s API. If there is, please leave a comment and share.
Here is an initial code that I found in Example Depot that removes the tabs:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
JColorChooser chooser = new JColorChooser(); // Retrieve the current set of panels AbstractColorChooserPanel[] oldPanels = chooser.getChooserPanels(); // Remove panels for (int i=0; i<oldPanels.length; i++) { String clsName = oldPanels[i].getClass().getName(); if (clsName.equals("javax.swing.colorchooser.DefaultSwatchChooserPanel")) { // Remove swatch chooser if desired chooser.removeChooserPanel(oldPanels[i]); } else if (clsName.equals("javax.swing.colorchooser.DefaultRGBChooserPanel")) { // Remove rgb chooser if desired chooser.removeChooserPanel(oldPanels[i]); } else if (clsName.equals("javax.swing.colorchooser.DefaultHSBChooserPanel")) { // Remove hsb chooser if desired chooser.removeChooserPanel(oldPanels[i]); } } JColorChooser.createDialog(null, "Dialog Title", false, chooser, null, null).setVisible(true); |
Just comment out the lines that call removeChooserPanel() method if you do not want those tabs to be removed.