Java Reference
In-Depth Information
Figure 14.2
Layout managers
Layout Managers
There are many useful layout managers with names that reflect the style in which
they position components. Figure 14.2 illustrates some of the most common layout
managers.
Perhaps the simplest layout manager is FlowLayout . As we discussed previously,
a FlowLayout positions components in a left-to-right, top-to-bottom flow, similar to
the way that words are arranged in a paragraph. If a row of components is too wide to
fit in the frame, the row wraps.
Consider the following code, which adds three components to a frame that uses a
FlowLayout :
JLabel label = new JLabel("Type your ZIP code: ");
JTextField field = new JTextField(5);
JButton button = new JButton("Submit");
frame.setLayout(new FlowLayout());
frame.add(label);
frame.add(field);
frame.add(button);
The graphical output that follows is produced when the frame is shown on the
screen. Resizing the window illustrates the wrapping behavior:
 
Search WWH ::




Custom Search