Module java.desktop
Package java.awt

Class FlowLayout

java.lang.Object
java.awt.FlowLayout
All Implemented Interfaces:
LayoutManager, Serializable

public class FlowLayout extends Object implements LayoutManager, Serializable
A flow layout arranges components in a directional flow, much like lines of text in a paragraph. The flow direction is determined by the container's componentOrientation property and may be one of two values:
  • ComponentOrientation.LEFT_TO_RIGHT
  • ComponentOrientation.RIGHT_TO_LEFT
Flow layouts are typically used to arrange buttons in a panel. It arranges buttons horizontally until no more buttons fit on the same line. The line alignment is determined by the align property. The possible values are:

For example, the following picture shows an applet using the flow layout manager (its default layout manager) to position three buttons:

Graphic of Layout for Three Buttons

Here is the code for this applet:


 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 assume its natural (preferred) size.

Since:
1.0
See Also: