JColorChooser: hide all panels by default and show only HSB panel

How to hide all panels by default on JColorChooser except HSB ?

And is it possible to show only HSB without JTabbedPane, just a panel

enter image description here

Thanks!

+4
source share
4 answers
 import javax.swing.*; import javax.swing.colorchooser.*; class ColorChooserTest { public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { JColorChooser cc = new JColorChooser(); AbstractColorChooserPanel[] panels = cc.getChooserPanels(); for (AbstractColorChooserPanel accp : panels) { if (accp.getDisplayName().equals("HSB")) { JOptionPane.showMessageDialog(null, accp); } } } }); } } 
+7
source

You can try: setChooserPanels method for this. More help here .

+4
source

This can also be done with a simple loop:

 AbstractColorChooserPanel[] panels = jColorChooser1.getChooserPanels(); for (AbstractColorChooserPanel accp : panels) { if(!accp.getDisplayName().equals("HSB")) { jColorChooser1.removeChooserPanel(accp); } } 
+1
source

If you want to remove panels, you can follow this approach. Here I delete all other panels except Swatches and RGB,

 AbstractColorChooserPanel[] panels=colorChooser.getChooserPanels(); for(AbstractColorChooserPanel p:panels){ String displayName=p.getDisplayName(); switch (displayName) { case "HSV": colorChooser.removeChooserPanel(p); break; case "HSL": colorChooser.removeChooserPanel(p); break; case "CMYK": colorChooser.removeChooserPanel(p); break; } 
0
source

Source: https://habr.com/ru/post/1393970/


All Articles