Microsoft KB Archive/225074

= PRB: AWT Components Only Use RGB Values (0..179) for Background Colors =

Article ID: 225074

Article Last Modified on 6/14/2006

-

APPLIES TO


 * Microsoft Java Virtual Machine

-



This article was previously published under Q225074



SYMPTOMS
RGB values greater than 179 are treated as value 255 when passed to the setBackground method on controls such as a java.awt.TextField.



CAUSE
The setBackground method calls the brighter method on the java.awt.Color object that is passed to it.



RESOLUTION
You can have the Component work as expected by providing an overridden class in place of the java.awt.Color object that setBackground is expecting. In this overridden class, the brighter method should return a reference to "this". See the "More Information" section for an example.



STATUS
This behavior is by design. To stay compatible with other, non-Microsoft virtual computers, this behavior will not change.



MORE INFORMATION
Use this class in place of java.awt.Color when you call setBackground to force the AWT Component to behave as expected: import java.awt.Color;

public class myColor extends Color { public myColor(float r,float g,float b){ super(r,g,b); } public myColor(int r,int g,int b){ super(r,g,b); } public myColor(int rgb){ super(rgb); }

public Color brighter{ return (Color)this; }

}

