[Lemma 1]

Java Colours


A colour in Java is modelled as a point in a 256x256x256 cube. The edges of the cube correspond to the red, blue and green intensity for the colour guns on your screen. That works out at over 16 million colours for the Java programmer to dazzle you with.

Explore the Java colour cube using the applet towards the top of this page. The level and Z axis values define a 256x256 slice through the colour cube. For example, if you choose "128" and "Green", you get the slice where the green intensity is fixed at 128 and the red and blue intensities vary from 0 to 255. Click on the display button to see a 16x16 grid that shows your slice at a resolution of 16. As you move the mouse over the grid, you'll see the intensity values for the cell you're on displayed in hexadecimal. The display is in hexadecimal because that's what you'd want to use in a Java program.

If the resolution of 16 is not enough for you, hold the shift key down and click on a cell in the grid to zoom in on the cell. When you've tired of that, come pack to the controls on this page to pick a different slice. That's all 16,777,216 colours for you to look at at your leisure.

You may well find that the correspondence between colours and RGB intensities isn't as smooth as it ought to be. This is a result of vagaries of the several layers of software that mediate between a Java RGB colour value and the electronics that drive your screen. If you zoom in on the irregular cells, you will very likely see that there are jagged holes in your colour cube.

All in all, it may just be simpler to stick with the predefined colours that Java provides. To explore the thirteen colours that are declared as public variables in the classs java.awt.Color, you can use the applet towards the bottom of this page: select a colour name and press display to create a window showing you the colour and the numerical RGB intensities for it.

This is a Java 1.0 applet; the colour model has not changed in Java 1.1. A new class SystemColor has been provided in Java 1.1 to help the programmer mimic the colours used by the windowing system.


Created by Rob Arthan [rda at lemma-one dot com]
Last updated: $Date: 2003/04/22 17:00:32 $
[Lemma 1]