
440
|
Chapter 11, Native Integration and Packaging
#87 Create an Inverse Black-and-White Theme
HACK
A Black-and-White Theme
A Metal theme is defined by a series of colors and fonts. The most impor-
tant ones are the three primary and three secondary colors. These define the
standard set of colors used for every widget on screen. Certain components
have additional colors, like the text selection, but almost everything is based
on these six. Example 11-9 is a theme that uses only white and black. It is
useful for embedded devices that can’t afford the hardware or memory
requirements of a color display.
Two of the primary colors are all white, and the third is black. The three sec-
ondary colors are just the reverse: two black and one white. This introduces
extra contrast. Each color controls a different part of the component. The
MetalTheme documentation is very sparse, so the only way to know what a
particular color will do is to try it. Without the theme, the screen will look
like Figure 11-17.
With the
InverseTheme installed, the window will look like Figure 11-18.
Example 11-9. A black-and-white Metal theme
import javax.swing.plaf.metal.*;
import javax.swing.plaf.ColorUIResource;
public class InverseTheme extends DefaultMetalTheme {
protected ColorUIResource getPrimary1( ) {
return new ColorUIResource(255,255,255);
}
protected ColorUIResource getPrimary2( ) {
return new ColorUIResource(0,0,0);
}
protected ...