2012-01-31 13 views

答えて

7
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); 
        } 
       } 
      } 
     }); 
    } 
} 
+1

また、[この回答](http://stackoverflow.com/a/9000014/418556)も参照してください。 –

4

試してみることができます:setChooserPanelsこれを行うJColorChooserの方法。その他のヘルプhere

0

あなたがパネルを削除したい場合は、ここでは、このアプローチに従うことができ、私はスウォッチや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; 
      } 
1

また、単純なループで行うことができます。

AbstractColorChooserPanel[] panels = jColorChooser1.getChooserPanels(); 
for (AbstractColorChooserPanel accp : panels) { 
    if(!accp.getDisplayName().equals("HSB")) { 
     jColorChooser1.removeChooserPanel(accp); 
    } 
} 
関連する問題