|< Day Day Up >|
A Visual Guide to Layout Managers
Several AWT and Swing classes provide layout managers for general use:
This section shows example GUIs that use these layout managers and
Every content pane is
Figure 1. BorderLayoutDemo is an example that uses BorderLayout .
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 .
class lets you implement an area that contains different components at different times (see Figure 3).
is often controlled by a combo box, the state of which determines which panel (
Figure 3. C ardLayoutDemo is an example that uses CardLayout .
FlowLayout 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 .
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 .
simply makes components equal in
Figure 6. GridLayoutDemo is an example that uses GridLayout .
SpringLayout 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 >|