United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6783910 java.awt.Color.brighter()/darker() methods make color opaque
JDK-6783910 : java.awt.Color.brighter()/darker() methods make color opaque

Details
Type:
Bug
Submit Date:
2008-12-11
Status:
Closed
Updated Date:
2012-03-22
Project Name:
JDK
Resolved Date:
2011-01-18
Component:
client-libs
OS:
solaris,generic
Sub-Component:
java.awt
CPU:
sparc,generic
Priority:
P2
Resolution:
Fixed
Affected Versions:
7
Fixed Versions:

Related Reports
Duplicate:

Sub Tasks

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
EVALUATION

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

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



Hardware and Software, Engineered to Work Together