Java 7 JColorChooser: Disable Transparency Slider

后端 未结 5 947
说谎
说谎 2020-12-19 04:35

JDK 7 added a new transparency slider to the JColorChooser:

\"enter

The proble

5条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-19 05:10

    Although it's implementation dependent, you can remove concrete subclasses of AbstractColorChooserPanel by name.

    This example removes all but the RGB panel:

    AbstractColorChooserPanel[] ccPanels = chooser.getChooserPanels();
    for (AbstractColorChooserPanel ccPanel : ccPanels) {
        System.out.println(ccPanel.getDisplayName());
        String name = ccPanel.getClass().getSimpleName();
        if (!"DefaultRGBChooserPanel".equals(name))
            tcc.removeChooserPanel(ccPanel);
    }
    

    This example restores the HSB panel:

    for (AbstractColorChooserPanel ccPanel : ccPanels) {
        String name = ccPanel.getClass().getSimpleName();
        if ("DefaultHSBChooserPanel".equals(name))
            tcc.addChooserPanel(ccPanel);
    }
    

    You'll need to determine the desired name(s) empirically.

提交回复
热议问题