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

ID: Q225074


The information in this article applies to:
  • Microsoft virtual machine


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 the latest Knowledge Base articles and other support information on Visual J++ and the SDK for Java, please see the following pages on the Microsoft Technical Support site:

http://support.microsoft.com/support/visualj/

http://support.microsoft.com/support/java/

© Microsoft Corporation 1999, All Rights Reserved.
Contributions by Joseph B. Hall, Microsoft Corporation

Additional query words: AWT Color

Keywords : kbSDKJava kbVJ kbGrpJava kbDSupport
Version : WINDOWS:
Platform : WINDOWS
Issue type : kbprb


Last Reviewed: November 16, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.