Java Reference
In-Depth Information
Figure 11.6
A BorderLayout (Figure 11.7) places up to five components in an arranged pattern: one in the
center and one each at the top, bottom, right, and left. Each of these positions may be empty,
so it may hold fewer than five components. The five positions are named CENTER, NORTH,
SOUTH, EAST, and WEST. There is no leftover space with a BorderLayout when the win-
dow is resized; it is all distributed (unevenly) between the components.
Figure 11.7
This layout may seem very specialized at first—one wonders how often this is needed. But in
practice, this is a surprisingly useful layout that is used in many applications. In BlueJ, for ex-
ample, both the main window and the editor use a BorderLayout as the main layout manager.
When a BorderLayout is resized, the middle component is the one that gets stretched in both
dimensions. The east and west components change in height but keep their width. The north
and south components keep their height, and only the width changes.
As the name suggests, a GridLayout is useful (Figure 11.8) for laying out components in an
evenly spaced grid. The numbers of rows and columns can be specified, and the GridLayout
manager will always keep all components at the same size. This can be useful to force buttons, for
Search WWH ::

Custom Search