United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6849805 Nimbus L&F: NimbusLookAndFeel.getDerivedColor() not always returns color2 for 1.0 midPoint
JDK-6849805 : Nimbus L&F: NimbusLookAndFeel.getDerivedColor() not always returns color2 for 1.0 midPoint

Details
Type:
Bug
Submit Date:
2009-06-10
Status:
Closed
Updated Date:
2012-03-22
Project Name:
JDK
Resolved Date:
2011-03-07
Component:
client-libs
OS:
generic
Sub-Component:
javax.swing
CPU:
generic
Priority:
P2
Resolution:
Fixed
Affected Versions:
7
Fixed Versions:

Related Reports
Backport:
Duplicate:

Sub Tasks

Description
The spec for javax.swing.plaf.nimbus.NimbusLookAndFeel.getDerivedColor(Color color1, Color color2, float midPoint) says:

     * @param midPoint The offset between color 1 and color 2, a value of 0.0 is
     *                 color 1 and 1.0 is color 2;

Exact second color is not always returned for 1.0 offset value.

Please see the following code sample:

------------------------------------------------------------------------------------
import java.awt.*;

public class Test {
    public static void main(String[] args) {
        class MyNibusLAF extends javax.swing.plaf.nimbus.NimbusLookAndFeel {
            public Color callGetDerivedColor(Color c1, Color c2, float midPoint) {
                return getDerivedColor(c1, c2, midPoint);
            }
        }
        Color secondColor = Color.BLACK;
        Color returnedColor = new MyNibusLAF().callGetDerivedColor(Color.WHITE, secondColor, 1.f);
        System.out.println("returnedColor = " + returnedColor);
        System.out.println("secondColor = " + secondColor);
    }
}
------------------------------------------------------------------------------------

Output will look:

returnedColor = javax.swing.plaf.ColorUIResource[r=1,g=1,b=1]
secondColor = java.awt.Color[r=0,g=0,b=0]


Color RGB components are not as expected.

                                    

Comments
EVALUATION

I believe this is caused by wrong rounding mode. Conversion to (int) rounds towards zero, whereas we should be rounding towards negative infinity. Math.round() does exactly what we need here.
                                     
2009-06-26



Hardware and Software, Engineered to Work Together