Java Reference
In-Depth Information
SELF-REVIEW QUESTIONS (see answers in Appendix N)
SR 7.28 When is a layout manager consulted?
SR 7.29 How does the flow layout manager behave?
SR 7.30 Describe the areas of a border layout.
SR 7.31 What effect does a glue component in a box layout have?
7.12 Borders
Java provides the ability to put a border around any Swing component. A bor-
der is not a component itself but rather defines how the edge of any component
should be drawn and has an important effect on the design of a GUI. A border
provides visual cues as to how GUI components are organized and can be used
to give titles to components. Figure 7.11 lists the predefined borders in the Java
standard class library.
The BorderFactory class is useful for creating borders for
components. It has many methods for creating specific types
of borders. A border is applied to a component by using the
component's setBorder method.
The program in Listing 7.24 demonstrates several types
of borders. It simply creates several panels, sets a different
border for each, and then displays them in a larger panel by using a grid layout.
KEY CONCEPT
Borders can be applied to Swing
components to group objects and
focus attention.
Border
Description
Empty Border
Puts buffering space around the edge of a component, but otherwise
has no visual effect.
Line Border
A simple line surrounding the component.
Etched Border
Creates the effect of an etched groove around a component.
Bevel Border
Creates the effect of a component raised above the surface or
sunken below it.
Titled Border
Includes a text title on or around the border.
Matte Border
Allows the size of each edge to be specified. Uses either a solid color
or an image.
Compound Border
A combination of two borders.
FIGURE 7.11 Component borders
 
Search WWH ::




Custom Search