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



The information in this article applies to:

  • Microsoft 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;
	}


}

REFERENCES

For support information about Visual J++ and the SDK for Java, visit the following Microsoft Web site:

Modification Type:MajorLast Reviewed:6/14/2006
Keywords:kbprb KB225074 kbAudDeveloper