Package java.awt |
![]() Previous |
![]() Java API |
![]() Index |
![]() Next |
public class java.awt.FlowLayout extends java.lang.Object implements java.awt.LayoutManager { // Fields public final static int CENTER; public final static int LEFT; public final static int RIGHT; // Constructors public FlowLayout(); public FlowLayout(int align); public FlowLayout(int align, int hgap, int vgap); // Methods public void addLayoutComponent(String name, Component comp); public void layoutContainer(Container target); public Dimension minimumLayoutSize(Container target); public Dimension preferredLayoutSize(Container target); public void removeLayoutComponent(Component comp); public String toString(); }
A Flow layout arranges components in a left-to-right flow, much like lines of text in a paragraph. Flow layouts are typically used to arrange buttons in a panel.
For example, the following picture shows an Applet using the flow layout manager (its default layout manager) to position three buttons:
Here is the applet code:
import java.awt.*; import java.applet.Applet; public class myButtons extends Applet { Button button1, button2, button3; public void init() { button1 = new Button("Ok"); button2 = new Button("Open"); button3 = new Button("Close"); add(button1); add(button2); add(button3); } }
A flow layout lets each component take its natural (preferred) size.
public final static int CENTER = 1This value indicates that each row of components should be centered.
public final static int LEFT = 0This value indicates that each row of components should be left justified.
public final static int RIGHT = 2This value indicates that each row of components should be right justified.
public FlowLayout()Creates a new flow layout manager with a centered alignment and a default 5-pixel horizontal and vertical gap.
public FlowLayout(int align)Creates a new flow layout manager with the indicated alignment and a default 5-pixel horizontal and vertical gap.
The alignment argument must be one of FlowLayout.LEFT, FlowLayout.RIGHT, or FlowLayout.CENTER.
Parameter Description align the alignment value
public FlowLayout(int align, int hgap, int vgap)Creates a new flow layout manager with the indicated alignment and the indicated horizontal and vertical gaps.
The alignment argument must be one of FlowLayout.LEFT, FlowLayout.RIGHT, or FlowLayout.CENTER.
Parameter Description align the alignment value hgap the horizontal gap between components vgap the vertical gap between components
public void addLayoutComponent(String name, Component comp)This method is not used by the flow layout manager.
Parameter Description name a tag comp the component to be added
public void layoutContainer(Container target)Lays out the container argument using this layout.
This method lets each component take its preferred size.
Most applications do not call this method directly. This method is called when a container calls its layout method .
Parameter Description target the container in which to do the layout See Also: Container .
public Dimension minimumLayoutSize(Container target)Determines the minimum size of the target container using this flow layout.
The minimum width needed to lay out the container's components is the total minimum width of each of the components, plus (ncomponents + 1) times the horizontal gap, plus the left and right inset, where ncomponents is the number of components in the container.
The minimum height needed to lay out the container's components is the greatest minimum height of the components, plus twice the vertical gap, plus the top and bottom insets.
Most applications do not call this method directly. This method is called when a container calls its layout method .
Return Value:
Returns the minimum dimensions needed to lay out the subcomponents of the specified container.
Parameter Description target the container in which to do the layout See Also: preferredLayoutSize .
public Dimension preferredLayoutSize(Container target)Determines the preferred size of the target container using this flow layout.
The preferred width to lay out the container's components is the total preferred width of each of the components, plus (ncomponents + 1) times the horizontal gap, plus the left and right inset, where ncomponents is the number of components in the container.
The preferred height to lay out the container's components is the greatest preferred height of the components, plus twice the vertical gap, plus the top and bottom insets.
Most applications do not call this method directly. This method is called when a container calls its preferredSize method .
Return Value:
Returns the preferred dimensions to lay out the subcomponents of the specified container.
Parameter Description parent the container in which to do the layout See Also: Container minimumLayoutSize .
public void removeLayoutComponent(Component comp)Removes the specified component from this layout.
Most applications do not call this method directly. This method is called when a container calls its remove or removeAll methods.
Parameter Description comp the component to be removed
public String toString()Return Value:
Returns a string representation of this layout.
Overrides:
toString in class Object .