Java Reference
In-Depth Information
Figure 7-2. Areas of border insets
Listing 7-1 shows a simple paintBorder() implementation that fills in the left and right
sides with a brighter color than the top and bottom.
Listing 7-1. Filled-in Border Inset Areas
public void paintBorder(Component c, Graphics g, int x, int y, int width,
int height) {
Insets insets = getBorderInsets(c);
Color color = c.getForeground();
Color brighterColor = color.brighter();
// Translate coordinate space
g.translate(x, y);
// Top
g.setColor(color);
g.fillRect(0, 0, width, insets.top);
// Left
g.setColor(brighterColor);
g.fillRect(0, insets.top, insets.left, height-insets.top-insets.bottom);
// Bottom
g.setColor(color);
g.fillRect(0, height-insets.bottom, width, insets.bottom);
Search WWH ::




Custom Search