简体   繁体   English

JColorChooser:隐藏所有默认面板并仅显示HSB面板

[英]JColorChooser: hide all default panels and show HSB panel only

How can I hide all default panels at JColorChooser except HSB ? 如何在除HSB之外的JColorChooser隐藏所有默认面板?

And is it possible to show just HSB without JTabbedPane, just plain panel 是否可以只显示没有JTabbedPane的HSB,只是简单的面板

在此输入图像描述

Thank you! 谢谢!

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

You can try: setChooserPanels method of JColorChooser to do this. 您可以尝试:JColorChooser的setChooserPanels方法来执行此操作。 More help here . 这里有更多帮助。

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

If you want to delete panels you can follow this approach Here I'm removing all the other panels except Swatches and RGB, 如果你想删除面板你可以遵循这种方法在这里我删除除了色板和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;
            }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM