SystemColor

In Java 1.1, AWT provides access to desktop color schemes, or themes. To give you an idea of how these themes work, with the Windows Standard scheme for the Windows desktop, buttons have a gray background with black text. If you use the control panel to change to a High Contrast Black scheme, the button's background becomes black and the text white. Prior to 1.1, Java didn't know anything about desktop colors: all color values were hard coded. If you asked for a particular shade of gray, you got that shade, and that was it; applets and applications had no knowledge of the desktop color scheme in effect, and therefore, wouldn't change in response to changes in the color scheme.

Starting with Java 1.1, you can write programs that react to changes in the color scheme: for example, a button's color will change automatically when you use the control panel to change the color scheme. To do so, you use a large number of constants that are defined in the SystemColor class. Although these constants are public static final, they actually have a very strange behavior. Your program is not allowed to modify them (like any other constant). However, their initial values are loaded at run-time, and their values may change, corresponding to changes in the color scheme. This has one important consequence for developers: you should not use equals()to compare a SystemColor with a "regular" Color; use the getRGB() methods of the colors you are comparing to ensure that you compare the current color value.[1] Using Desktop Colors contains a usage example.

[1] The omission of an equals() method that can properly compare a SystemColor with a Color is unfortunate.

Because SystemColor is a subclass of Color, you can use a SystemColor anywhere you can use a Color object. You will never create your own SystemColor objects; there is no public constructor. The only objects in this class are the twenty or so SystemColor constants.

SystemColor Methods

Constants

There are two sets of constants within SystemColor. The first set provides names for indices into the internal system color lookup table; you will probably never need to use these. All of them have corresponding constants in the second set, except SystemColor.NUM_COLORS, which tells you how many SystemColor constants are in the second set.

public final static int ACTIVE_CAPTION
public final static int ACTIVE_CAPTION_BORDER
public final static int ACTIVE_CAPTION_TEXT
public final static int CONTROL
public final static int CONTROL_DK_SHADOW
public final static int CONTROL_HIGHLIGHT
public final static int CONTROL_LT_HIGHLIGHT
public final static int CONTROL_SHADOW
public final static int CONTROL_TEXT
public final static int DESKTOP
public final static int INACTIVE_CAPTION
public final static int INACTIVE_CAPTION_BORDER
public final static int INACTIVE_CAPTION_TEXT
public final static int INFO
public final static int INFO_TEXT
public final static int MENU
public final static int MENU_TEXT
public final static int NUM_COLORS
public final static int SCROLLBAR
public final static int TEXT
public final static int TEXT_HIGHLIGHT
public final static int TEXT_HIGHLIGHT_TEXT
public final static int TEXT_INACTIVE_TEXT
public final static int TEXT_TEXT
public final static int WINDOW
public final static int WINDOW_BORDER
public final static int WINDOW_TEXT

The second set of constants is the set of SystemColors you use when creating Component objects, to ensure they appear similar to other objects in the user's desktop environment. By using these symbolic constants, you can create new objects that are well integrated into the user's desktop environment, making it easier for the user to work with your program.

g.setColor(SystemColor.controlText); 

NOTE:

Every platform does not fully support every system color. However, on platforms that do not provide natural values for some constants, Java selects reasonable alternate colors.

If you are going to be working only with Java's prefabricated components (Button, List, etc.), you don't have to worry about system colors; the component's default colors will be set appropriately. You are most likely to use system colors if you are creating your own components. In this case, you will use system colors to make your component emulate the behavior of other components; for example, you will use controlText as the color for drawing text, activeCaption as the background for the caption of an active window, and so on. Constructors

There are no public constructors for SystemColor. If you need to create a new color, use the Color class described previously. Miscellaneous methods

java.awt.SystemColor[i=12]