will honor these requests if at all possible, while maintaining the integrity of the layout
policy. You may override these methods for controls that you subclass. Default values are
provided otherwise.
Java has several predefined LayoutManager classes, several of which are described
next. You can use the layout manager that best fits your application.
FlowLayout
FlowLayout is the default layout manager. This is the layout manager that the preceding
examples have used. FlowLayout implements a simple layout style, which is similar to
how words flow in a text editor. The direction of the layout is governed by the container 's
component orientation property, which, by default, is left to right, top to bottom. Therefore,
by default, components are laid out line-by-line beginning at the upper-left corner. In all
cases, when a line is filled, layout advances to the next line. A small space is left between
each component, above and below, as well as left and right. Here are the constructors for
FlowLayout:
FlowLayout( )
FlowLayout(int how)
FlowLayout(int how, int horz, int vert)
The first form creates the default layout, which centers components and leaves five pixels of
space between each component. The second form lets you specify how each line is aligned.
Valid values for how are as follows:
FlowLayout.LEFT
FlowLayout.CENTER
FlowLayout.RIGHT
FlowLayout.LEADING
FlowLayout.TRAILING
These values specify left, center, right, leading edge, and trailing edge alignment, respectively.
The third constructor allows you to specify the horizontal and vertical space left between
components in horz and vert, respectively.
Here is a version of the CheckboxDemo applet shown earlier in this chapter, modified
so that it uses left-aligned flow layout:
// Use left-aligned flow layout.
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*
<applet code="FlowLayoutDemo" width=250 height=200>
</applet>
*/
public class FlowLayoutDemo extends Applet
implements ItemListener {
String msg = "";
Checkbox winXP, winVista, solaris, mac;
Search WWH :
Custom Search
Previous Page
Java SE 6 Topic Index
Next Page
Java SE 6 Bookmarks
Home