2012-01-31 88 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)。 – 2012-01-31 13:00:32

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