Java Reference
In-Depth Information
// Right
g.setColor(brighterColor);
g.fillRect(width-insets.right, insets.top, insets.right,
height-insets.top-insets.bottom);
// Translate coordinate space back
g.translate(-x, -y);
}
When creating your own borders, you'll frequently find yourself filling in the same nonover-
lapping rectangular regions. The use of the translate() method of Graphics simplifies the
specification of the drawing coordinates. Without translating the coordinates, you would need
to offset the drawing by the origin (x, y).
Caution You cannot take a shortcut by inserting g.fillRect(x, y, width, height) , because this
would fill in the entire component area, not just the border area.
getBorderInsets()
The getBorderInsets() method returns the space necessary to draw a border around the given
component c as an Insets object. It has the following definition:
public Insets getBorderInsets(Component c)
These inset areas, shown in Figure 7-2, define the only legal area in which a border can be
drawn. The Component argument allows you to use some of its properties to determine the size
of the insets area.
Caution You can ask the component argument for font-sizing information to determine the insets' size,
but if you ask about the size of the component, a StackOverflowError occurs because the size of the
component is dependent on the size of the border insets.
isBorderOpaque()
Borders can be opaque or transparent. The isBorderOpaque() method returns true or false , to
indicate which form the border is. It has the following definition:
public boolean isBorderOpaque()
 
Search WWH ::




Custom Search