Java Glossary : colour

CMP home Java glossary home Menu no menu Last updated 2004-06-28 by Roedy Green ©1996-2004 Canadian Mind Products

Java definitions: 0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

You are here : home : Java Glossary : C words : colour.

colour
This entry is about colour in general, not just the java.awt.Color class. Note the American spelling of colour missing the u. Often your colours will be mangled when you run them on some other platform or browser than the one you developed with. Some platforms only support 256 colours. Colours with the following magic values as the R G or B component are most likely to survive unmolested: 0, 51, 102, 153, 204, 255 or 0x00, 0x33, 0x66, 0x99, 0xcc, 0xff.

Click any ball to view the corresponding colour palette.

Named Colours button Alphabetically button BHS: by Brightness, Hue, Saturation button HBS: by Hue, Brightness, Saturation button SBH: by Saturation, Brightness, Hue
button RGB: Numerically button BSH: by Brightness, Saturation, Hue button HSB: by Hue, Saturation, Brightness button SHB: by Saturation, Hue, Brightness
Numbered Colours button HTML 3.2 button Websafe button Rainbow button X11
Selected Colours button Pale button Dark button Simple button Greys button Colour Schemes
The above colour chart shows Netscape's 133 standard colours, and HTML 3.2's 16 standard colours. It shows the colours displayed eight ways, (colour on white, colour on black, black on colour, white on colour) both using alpha names and hex names. You can check out your browser for Netscape colour compatibility. It shows the Standard Netscape 7.02 alpha names such as "aliceblue" and also the hex, RGB an HSB values both as HTML and raw ASCII text.

Under the Hood

The java.awt.Color class internally creates a 32 bit descriptor of a colour composed of 4 8-bit unsigned bytes. A R G B.

A = alpha channel that measures opacity. 0 = 100% transparent, 255 = 100% opaque.
R = red channel that measures redness. 0 = black, 255 = intense red.
G = green channel that measures greenness. 0 = black, 255 = intense green.
B = blue channel that measures blueness. 0 = black, 255 = intense blue.

So 0.0.0.0 would be a totally transparent black colour, and 255.255.255.255 would be a totally opaque white. I have discovered by experiment that if you want transparent backgrounds that you can save variable tranparency png files if you use this magic combination:

Controlling Colour in Java

Note that you use Component.setForeground() and Component.setBackground() to control the colours of a component. However, in a paint or paintComponent method, you use Graphics.setColor() to paint both the background and foreground, e.g.

// paint background
g.setColor( getBackground() );
g.fillRect( 0, 0, width, height );

// paint foreground
g.setColor( getForeground() );
g.drawString( "hello", x, y );

Color transparent = new Color( 0x00ffffff, true );
BufferedImage bufferedImage = new BufferedImage ( width, height, BufferedImage.TYPE_4BYTE_ABGR_PRE );

The SystemColor class control the overall AWT colour scheme : available:
ColorSaver ¤ Colour blind colour chart ¤ Colour Vision Test as movie ¤ Colour Vision Test ¤ CYMK ¤ Font Shower Amanuensis: shows fonts in a variety of families, styles, sizes and colours ¤ frequency ¤ HSB ¤ Image ¤ Lynda Weinman's essay: browser-safe colours ¤ Netscape ¤ pseudograys: Rich Franzen's essay and code on smoother gray scales ¤ RGB ¤ wavelength ¤ Website Tips


CMP logo
CMP_home
home
Canadian Mind Products CSS
HTML Checked!
ICRA ratings logo
mindprod.com IP:[24.87.56.253]
Your IP:[80.134.30.163]
You are visitor number 3516.
Please send errors, omissions and suggestions
to improve this page to Roedy Green.
You can get a fresh copy of this page from: or possibly from your local J: drive mirror:
http://mindprod.com/jgloss/colour.html J:\mindprod\jgloss\colour.html