start page | rating of books | rating of authors | reviews | copyrights

Book Home Java Enterprise in a Nutshell Search this book

3.10. Borders

Every Swing component inherits a border property from JComponent, so you can call setBorder() to specify a Border object for a Swing component. This Border object displays some kind of decoration around the outside of the component. The javax.swing.border package contains this Border interface and a number of useful implementations of it. Table 3-1 lists the available border styles, and Figure 3-2 illustrates them.

Table 3-1. Swing Border Styles

Border Description
BevelBorder

Gives the component a beveled edge that makes it appear raised or lowered.

CompoundBorder

Combines two other Border types to create a compound border.

EmptyBorder

A border with no appearance. This is a useful way to place an empty margin around a component.

EtchedBorder

Draws a line around the component, using a 3D effect that makes the line appear etched into or raised out of the surrounding container.

LineBorder

Draws a line, with a color and thickness you specify, around the component.

MatteBorder

Draws the border using a solid color or a tiled image. You specify the border dimensions for all four sides.

SoftBevelBorder

Like BevelBorder, but with somewhat more complex graphics that give the bevel a softer edge.

TitledBorder

A border that combines text with an EtchedBorder or any other border you specify.

figure

Figure 3-2. Swing border styles

The Border implementations defined in javax.swing.border cover just about every possible border you are likely to want to display. But if you ever find yourself needing a specialized border, simply implement the Border interface yourself.

Most of the Border implementations in javax.swing.border are immutable objects, designed to be shared. If two components have the same style of border, they can use the same Border immutable object. The javax.swing.BorderFactory class contains static methods that return various commonly used Border objects suitable for sharing.



Library Navigation Links

Copyright © 2001 O'Reilly & Associates. All rights reserved.