java.awt

Class FlowLayout

  • java.lang.Object
    • java.awt.FlowLayout
  • All Implemented Interfaces:
    LayoutManager, java.io.Serializable
    public class FlowLayout extends java.lang.Object implements LayoutManager, java.io.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:
    JDK1.0
    See Also:
    ComponentOrientation, Serialized Form
    • Fields 
      Modifier and Type Field and Description
      Ordinary member indicator CENTER Reveal DetailHide Detail
      This value indicates that each row of components should be centered.
      Ordinary member indicator LEADING Reveal DetailHide Detail
      This value indicates that each row of components should be justified to the leading edge of the container's orientation, for example, to the left in left-to-right orientations.
      Ordinary member indicator LEFT Reveal DetailHide Detail
      This value indicates that each row of components should be left-justified.
      Ordinary member indicator RIGHT Reveal DetailHide Detail
      This value indicates that each row of components should be right-justified.
      Ordinary member indicator TRAILING Reveal DetailHide Detail
      This value indicates that each row of components should be justified to the trailing edge of the container's orientation, for example, to the right in left-to-right orientations.
    • Constructors 
      Constructor and Description
      Ordinary member indicator FlowLayout Reveal DetailHide Detail
      Constructs a new FlowLayout with a centered alignment and a default 5-unit horizontal and vertical gap.
      Ordinary member indicator FlowLayout Reveal DetailHide Detail
      Constructs a new FlowLayout with the specified alignment and a default 5-unit horizontal and vertical gap.
      Ordinary member indicator FlowLayout Reveal DetailHide Detail
      Creates a new flow layout manager with the indicated alignment and the indicated horizontal and vertical gaps.
    • Methods 
      Modifier and Type Method and Description
      Ordinary member indicator addLayoutComponent Reveal DetailHide Detail
      Adds the specified component to the layout.
      Ordinary member indicator getAlignment Reveal DetailHide Detail
      Gets the alignment for this layout.
      Ordinary member indicator getAlignOnBaseline Reveal DetailHide Detail
      Returns true if components are to be vertically aligned along their baseline.
      Ordinary member indicator getHgap Reveal DetailHide Detail
      Gets the horizontal gap between components and between the components and the borders of the Container
      Ordinary member indicator getVgap Reveal DetailHide Detail
      Gets the vertical gap between components and between the components and the borders of the Container.
      Ordinary member indicator layoutContainer Reveal DetailHide Detail
      Lays out the container.
      Ordinary member indicator minimumLayoutSize Reveal DetailHide Detail
      Returns the minimum dimensions needed to layout the visible components contained in the specified target container.
      Ordinary member indicator preferredLayoutSize Reveal DetailHide Detail
      Returns the preferred dimensions for this layout given the visible components in the specified target container.
      Ordinary member indicator removeLayoutComponent Reveal DetailHide Detail
      Removes the specified component from the layout.
      Ordinary member indicator setAlignment Reveal DetailHide Detail
      Sets the alignment for this layout.
      Ordinary member indicator setAlignOnBaseline Reveal DetailHide Detail
      Sets whether or not components should be vertically aligned along their baseline.
      Ordinary member indicator setHgap Reveal DetailHide Detail
      Sets the horizontal gap between components and between the components and the borders of the Container.
      Ordinary member indicator setVgap Reveal DetailHide Detail
      Sets the vertical gap between components and between the components and the borders of the Container.
      Overridden member indicator toString Reveal DetailHide Detail
      Returns a string representation of this FlowLayout object and its values.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
This document was created by Dulcet from the OpenJDK sources. Copyright © 1993, 2012 Oracle and/or its affiliates. All rights reserved.

SourceForge