| < Day Day Up > |
A Visual Guide to Layout ManagersSeveral AWT and Swing classes provide layout managers for general use:
This section shows example GUIs that use these layout managers and
BorderLayout
Every content pane is
Figure 1. BorderLayoutDemo is an example that uses BorderLayout .
BoxLayout
The
BoxLayout
class puts components in a single row or column (see Figure 2). It respects the components'
Figure 2. BoxLayoutDemo is an example that uses BoxLayout .
CardLayout
The
CardLayout
class lets you implement an area that contains different components at different times (see Figure 3).
CardLayout
is often controlled by a combo box, the state of which determines which panel (
Figure 3. C ardLayoutDemo is an example that uses CardLayout .
FlowLayoutFlowLayout is the default layout manager for every JPanel (see Figure 4). It simply lays out components in a single row, starting a new row if its container isn't sufficiently wide. Both panels in CardLayoutDemo , shown in Figure 3, use FlowLayout . For further details, see How to Use FlowLayout (page 479) in Chapter 8. Figure 4. F lowLayoutDemo is an example that uses FlowLayout .
GridBagLayout
GridBagLayout
is a sophisticated, flexible layout manager. It aligns components by placing them within a grid of
Figure 5. GridBagLayoutDemo is an example that uses GridBagLayout .
GridLayout
GridLayout
simply makes components equal in
Figure 6. GridLayoutDemo is an example that uses GridLayout .
SpringLayoutSpringLayout is a flexible layout manager designed for GUI builders (see Figure 7). It lets you specify precise relationships between the edges of components under its control. For example, you might define the left edge of one component as a certain distance (which can be dynamically calculated) from the right edge of a second component. For further details, see How to Use SpringLayout (page 492) in Chapter 8. Figure 7. Both SpringBox and SpringForm are examples that use SpringLayout .
|
| < Day Day Up > |