Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8051548

JColorChooser should have a way to disable transparency controls

    XMLWordPrintable

Details

    • b82
    • x86
    • windows_7

    Backports

      Description

        FULL PRODUCT VERSION :


        A DESCRIPTION OF THE PROBLEM :
        In Java 7, alpha/transparency controls were added to most tabs of the JColorChooser dialog. Transparent colors are not applicable to all uses of these dialogs but there is no way in the API to disable or hide the new transparency controls. Applications could derive a new color value having full alpha from the color returned from the dialog, but this still leaves the controls on screen, which will mislead and confuse users of the application.

        This has caused some annoyance, with developers resorting to ugly, unportable, reflection hacks to hide the controls. See: https://stackoverflow.com/questions/12026767/java-7-jcolorchooser-disable-transparency-slider

        In another case, the best available suggestion was to rewrite the color choosers from scratch to get rid of the controls. See: https://stackoverflow.com/questions/15227644/rgb-only-jcolorchooser-java-7

        Neither of those is a nice workaround.

        When I was searching to see if this report was a duplicate, I found an old request asking for transparency controls to be added to the JColorChooser (https://bugs.openjdk.java.net/browse/JDK-4332255) which was closed as "Won't Fix" at the time, on the basis that: "adding alpha channel selection may not appropriate for a general purpose toolkit". Kind of proves the point.

        So, there should be a way in the JColorChooser class to turn the transparency controls on and off. Principal API would be something like this:

            /**
             * Sets whether color chooser panels on this color chooser should display controls
             * for configuring the transparency (alpha value) of a color. This will fire a
             * {@code PropertyChangeEvent} for the property named "showTransparencyControls".
             *
             * <p>The value is a hint and may not be applicable to all types of chooser panel.
             *
             * <p>The default value is {@code true}.
             *
             * @param show whether to show color transparency controls
             * @see #getShowTransparencyControls()
             */
            public void setShowTransparencyControls(boolean show);
            
            /**
             * Gets whether color chooser panels on this color chooser should display controls
             * for configuring the transparency (alpha value) of a color.
             *
             * @return whether to show color transparency controls
             * @see #setShowTransparencyControls(boolean)
             */
            public boolean getShowTransparencyControls();

        Additionally, I'd suggest that there be an overload of the showDialog method that includes the same option as a parameter, as that is the most common way to use JColorChooser.


        REPRODUCIBILITY :
        This bug can be reproduced always.

        Attachments

          Issue Links

            Activity

              People

                alexsch Alexandr Scherbatiy
                webbuggrp Webbug Group
                Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved: