JDK-6783910 : java.awt.Color.brighter()/darker() methods make color opaque
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 7
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • OS: generic,solaris
  • CPU: generic,sparc
  • Submitted: 2008-12-11
  • Updated: 2017-05-16
  • Resolved: 2011-01-18
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7
7 b121Fixed
Related Reports
Duplicate :  
Description
Java SE specification states for java.awt.Color.brighter()/darker() methods:

For instance "darker"
  "This method applies an arbitrary scale factor to each of the three RGB 
   components of this Color to create a darker version of this Color."

This means that alpha component must remain unchanged, however it is not
the case for many Java implementations: 1.4.2, 5.0, 6.0, 7.

The code snippet helps to reproduce the problem:
-------------------------------------------------
import java.awt.Color;

public class TestColor {

    private void test(boolean direction)  {
        Color color = new Color(20, 20, 20, 125);
        System.out.println(color.getAlpha());
        final int initialAlpha = color.getAlpha();        
        for (int i = 0; i < 3; i++) {
            if (direction) {
                color = color.brighter();               
            } else {
                color = color.darker();
            }
            if (color.getAlpha() != initialAlpha) {
                System.out.println(direction ? "Color.brighter() failed: " + color.getAlpha() + " " + initialAlpha :
                                               "Color.darker() failed: " + color.getAlpha() + " " + initialAlpha);
            }
        }
    }

    public static void main(String argv[]) {
        new TestColor().test(true); 
        new TestColor().test(false);
   }
}
--------------------------------------------------------------

Comments
SUGGESTED FIX CCC proposal: http://ccc.sfbay/6783910
23-11-2010

EVALUATION We don't want to chenge the behavior taking into account where we are with JDK7 so the spec change would work here.
13-08-2010