JDK-4087969 : java.awt.Color.brighter() does not work properly!!!
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.1,1.1.3,1.1.5
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: generic,solaris_2.5,windows_nt
  • CPU: generic,x86
  • Submitted: 1997-10-22
  • Updated: 1998-08-17
  • Resolved: 1998-02-13
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.
Other Other
1.1.7 b01Fixed 1.2.0Fixed
Related Reports
Duplicate :  
Description

Name: sg39081			Date: 10/22/97


The brighter() method in the java.awt.Color class
does not work under certain conditions. For example
if I have chosen the color to be blue: RGB=(0,0,255)
it does not return a brighter version of the color.
In the source code, a new instance of Color is
returned which has the original color's RGB values
multiplied by a certain factor, but what if one of
the RGB values is 0, which mutliplied is still 0!
So a brighter version of pure blue is pure blue if
you execute the method... But aren't you supposed to
have a "lighter blue" as the brighter version...
------------
Or: Color.black.brighter() will not return a shade
of gray but pure black!
------------
Or maybe I'm confusing the technical definition of
brighter???

import java.awt.*;
import java.awt.event.*;

public class b
{
    Frame f;
    ColorComponent c1;
    Button b1;

    b(Color c)
    {
        f = new Frame();
        c1 = new ColorComponent(c);
        b1 = new Button("Brighter");

        f.add("North", c1);
        c1.addMouseListener(c1);
        b1.addMouseListener(new MouseAdapter()
            {
                public void mouseClicked(MouseEvent e)
                {
                    Color new_c = c1.myColor.brighter();
                    System.out.println("New color=(" +
                            new_c.getRed() + "," +
                            new_c.getGreen() + "," +
                            new_c.getBlue() + ")"
                            );
                    c1.setColor(new_c);
                    c1.paint(c1.getGraphics());
                }
            }
        );
        f.add("South", b1);

        f.pack();
        f.setVisible(true);
    }

    public static void main(String[] args)
    {
        b my_b;
        float r, g, b;
        if (args.length ==3)
        {
            r = new Float(args[0]).floatValue();
            g = new Float(args[1]).floatValue();
            b = new Float(args[2]).floatValue();
            my_b = new b(new Color(r/255.0f, g/255.0f, b/255.0f));
        }
        else
            my_b = new b(new Color(0,100,100));
    }
}

class ColorComponent extends Component implements MouseListener
{
        public ColorComponent() { }

        public ColorComponent(Color c)
        {
                myColor = c;
        }

        public Dimension getPreferredSize()
        {
                return new Dimension(100,100);
        }
         public void paint(Graphics g)
        {
                g.setColor(myColor);
                g.fillRect(0,0,100,100);
        }
        public void setColor(Color c)
        {
            myColor = c;
        }

        public void mouseClicked(MouseEvent me)
        {
                if (myColor.equals(Color.red))
                        System.out.println("Red");
                else
                        System.out.println("Blue");
        }
        public void mouseEntered(MouseEvent me) { }
        public void mouseExited(MouseEvent me) { }
        public void mousePressed(MouseEvent me) { }
        public void mouseReleased(MouseEvent me) { }

        public Color myColor = Color.black;
}

======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: generic FIXED IN: 1.1.7 1.2beta4 INTEGRATED IN: 1.1.7 1.2beta4 VERIFIED IN: 1.1.7
14-06-2004

WORK AROUND Name: sg39081 Date: 10/22/97 You could possibly convert it into the HSB model and increase the Brightness setting, and convert it back. ======================================================================
11-06-2004

EVALUATION 2D group would like to have black.brighter() as grey, but pure blue.brighter should remain as pure blue. So the change will be if all the RGB components are zero, change them to grey. xianfa.deng@Eng 1997-11-20 This bug verified as fixed via regression testing using jdk117h. Changes made into Color.java in JDK1.1.7 and 1.2beta4. xianfa.deng@Eng 1998-02-13 john.s.lee@Eng 1998-08-17 This bug verified as fixed via regression testing using jdk117h. john.s.lee@Eng 1998-08-17
13-02-1998