问题
How can I hide all default panels at JColorChooser
except HSB?
And is it possible to show just HSB without JTabbedPane, just plain panel
Thank you!
回答1:
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);
}
}
}
});
}
}
回答2:
You can try: setChooserPanels method of JColorChooser to do this. More help here.
回答3:
It can be also done with the simple loop:
AbstractColorChooserPanel[] panels = jColorChooser1.getChooserPanels();
for (AbstractColorChooserPanel accp : panels) {
if(!accp.getDisplayName().equals("HSB")) {
jColorChooser1.removeChooserPanel(accp);
}
}
回答4:
If you want to delete panels you can follow this approach Here I'm removing all the 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;
}
来源:https://stackoverflow.com/questions/9079807/jcolorchooser-hide-all-default-panels-and-show-hsb-panel-only