Package java.awt Previous
Previous
Java API
Java API
Index
Index
Next
Next

Class FlowLayout

Fields , Constructors , Methods

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.


Fields


CENTER

public final static int CENTER = 1 

This value indicates that each row of components should be centered.


LEFT

public final static int LEFT = 0 

This value indicates that each row of components should be left justified.


RIGHT

public final static int RIGHT = 2 

This value indicates that each row of components should be right justified.


Constructors


FlowLayout

public FlowLayout() 

Creates a new flow layout manager with a centered alignment and a default 5-pixel horizontal and vertical gap.


FlowLayout

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.

ParameterDescription
align the alignment value


FlowLayout

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.

ParameterDescription
align the alignment value
hgap the horizontal gap between components
vgap the vertical gap between components


Methods


addLayoutComponent

public void addLayoutComponent(String  name, Component  comp) 

This method is not used by the flow layout manager.

ParameterDescription
name a tag
comp the component to be added


layoutContainer

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 .

ParameterDescription
target the container in which to do the layout

See Also: Container .


minimumLayoutSize

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.

ParameterDescription
target the container in which to do the layout

See Also: preferredLayoutSize .


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.

ParameterDescription
parent the container in which to do the layout

See Also: Container minimumLayoutSize .


removeLayoutComponent

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.

ParameterDescription
comp the component to be removed


toString

public String toString() 

Return Value:

Returns a string representation of this layout.

Overrides:

toString in class Object .



Top© 1996 Sun Microsystems, Inc. All rights reserved.