Class VerticalFlowLayout

java.lang.Object
de.soldin.awt.VerticalFlowLayout
All Implemented Interfaces:
LayoutManager, Serializable

public class VerticalFlowLayout extends Object implements LayoutManager, Serializable
This flow layout arranges components in a directional flow, much like lines of text in a paragraph but vertically. 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
Don't be confused. These are simply interpreted as standard TOP_TO_BOTTOM (LEFT_TO_RIGHT) or BOTTOM_TO_TOP (RIGHT_TO_LEFT) as ComponentOrientation does not provide vertical orientation values.

We arrange components vertically until no more components fit on the same column. The vertical alignment is determined by the align property. The possible values are:

See main() method in source code for an example on how to use it.

See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    This value indicates that each column of components should be bottom-justified.
    static final int
    This value indicates that each column of components should be centered.
    static final int
     
    static final int
    This value indicates that each column of components should be top-justified.
    static final int
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a new VerticalFlowLayout with a centered alignment and a default 5-unit horizontal and vertical gap.
    VerticalFlowLayout(int align)
    Constructs a new VerticalFlowLayout with the specified alignment and a default 5-unit horizontal and vertical gap.
    VerticalFlowLayout(int align, int hgap, int vgap)
    Creates a new flow layout manager with the indicated alignment and the indicated horizontal and vertical gaps.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Adds the specified component to the layout.
    int
    Gets the alignment for this layout.
    double
     
    int
    Gets the horizontal gap between components and between the components and the borders of the Container
    int
    Gets the vertical gap between components and between the components and the borders of the Container.
    int
    Sets the wrap mode for this layout
    void
    Lays out the container.
    static void
    main(String[] args)
     
    Returns the minimum dimensions needed to layout the visible components contained in the specified target container.
    Returns the preferred dimensions for this layout given the visible components in the specified target container.
    void
    Removes the specified component from the layout.
    void
    setAlignment(int align)
    Sets the alignment for this layout.
    void
    setDefaultRatio(double defRatio)
    Set a default layout ratio.
    void
    setHgap(int hgap)
    Sets the horizontal gap between components and between the components and the borders of the Container.
    void
    setVgap(int vgap)
    Sets the vertical gap between components and between the components and the borders of the Container.
    void
    setWrapMode(int wrapMode)
    Sets the alignment for this layout.
    Returns a string representation of this VerticalFlowLayout object and its values.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • TOP

      public static final int TOP
      This value indicates that each column of components should be top-justified.
      See Also:
    • CENTER

      public static final int CENTER
      This value indicates that each column of components should be centered.
      See Also:
    • BOTTOM

      public static final int BOTTOM
      This value indicates that each column of components should be bottom-justified.
      See Also:
    • WIDTH

      public static final int WIDTH
      See Also:
    • HEIGHT

      public static final int HEIGHT
      See Also:
  • Constructor Details

    • VerticalFlowLayout

      public VerticalFlowLayout()
      Constructs a new VerticalFlowLayout with a centered alignment and a default 5-unit horizontal and vertical gap.
    • VerticalFlowLayout

      public VerticalFlowLayout(int align)
      Constructs a new VerticalFlowLayout with the specified alignment and a default 5-unit horizontal and vertical gap. The value of the alignment argument must be one of VerticalFlowLayout.TOP, VerticalFlowLayout.BOTTOM, or VerticalFlowLayout.CENTER
      Parameters:
      align - the alignment value
    • VerticalFlowLayout

      public VerticalFlowLayout(int align, int hgap, int vgap)
      Creates a new flow layout manager with the indicated alignment and the indicated horizontal and vertical gaps.

      The value of the alignment argument must be one of VerticalFlowLayout.TOP, VerticalFlowLayout.BOTTOM , or VerticalFlowLayout.CENTER.

      Parameters:
      align - the alignment value
      hgap - the horizontal gap between components and between the components and the borders of the Container
      vgap - the vertical gap between components and between the components and the borders of the Container
  • Method Details

    • getAlignment

      public int getAlignment()
      Gets the alignment for this layout. Possible values are VerticalFlowLayout.TOP, VerticalFlowLayout.BOTTOM or VerticalFlowLayout.CENTER,
      Returns:
      the alignment value for this layout
      See Also:
    • setAlignment

      public void setAlignment(int align)
      Sets the alignment for this layout. Possible values are
      • VerticalFlowLayout.TOP
      • VerticalFlowLayout.BOTTOM
      • VerticalFlowLayout.CENTER
      Parameters:
      align - one of the alignment values shown above
      See Also:
    • getWrapMode

      public int getWrapMode()
      Sets the wrap mode for this layout
      Returns:
      int wrap mode
    • setWrapMode

      public void setWrapMode(int wrapMode)
      Sets the alignment for this layout. Possible values are
      • VerticalFlowLayout.WIDTH (default)
      • VerticalFlowLayout.HEIGHT
      Parameters:
      wrapMode - wrap mode to use : WIDTH (default) or HEIGHT
    • getDefaultRatio

      public double getDefaultRatio()
    • setDefaultRatio

      public void setDefaultRatio(double defRatio)
      Set a default layout ratio. See defRatio comment above.
      Parameters:
      defRatio - default ratio (width/height)
    • getHgap

      public int getHgap()
      Gets the horizontal gap between components and between the components and the borders of the Container
      Returns:
      the horizontal gap between components and between the components and the borders of the Container
      Since:
      JDK1.1
      See Also:
    • setHgap

      public void setHgap(int hgap)
      Sets the horizontal gap between components and between the components and the borders of the Container.
      Parameters:
      hgap - the horizontal gap between components and between the components and the borders of the Container
      Since:
      JDK1.1
      See Also:
    • getVgap

      public int getVgap()
      Gets the vertical gap between components and between the components and the borders of the Container.
      Returns:
      the vertical gap between components and between the components and the borders of the Container
      Since:
      JDK1.1
      See Also:
    • setVgap

      public void setVgap(int vgap)
      Sets the vertical gap between components and between the components and the borders of the Container.
      Parameters:
      vgap - the vertical gap between components and between the components and the borders of the Container
      See Also:
    • addLayoutComponent

      public void addLayoutComponent(String name, Component comp)
      Adds the specified component to the layout. Not used by this class.
      Specified by:
      addLayoutComponent in interface LayoutManager
      Parameters:
      name - the name of the component
      comp - the component to be added
    • removeLayoutComponent

      public void removeLayoutComponent(Component comp)
      Removes the specified component from the layout. Not used by this class.
      Specified by:
      removeLayoutComponent in interface LayoutManager
      Parameters:
      comp - the component to remove
      See Also:
    • preferredLayoutSize

      public Dimension preferredLayoutSize(Container target)
      Returns the preferred dimensions for this layout given the visible components in the specified target container.
      Specified by:
      preferredLayoutSize in interface LayoutManager
      Parameters:
      target - the container that needs to be laid out
      Returns:
      the preferred dimensions to lay out the subcomponents of the specified container
      See Also:
    • minimumLayoutSize

      public Dimension minimumLayoutSize(Container target)
      Returns the minimum dimensions needed to layout the visible components contained in the specified target container. Not supported by this class! Returns preferredLayoutSize(Container) instead.
      Specified by:
      minimumLayoutSize in interface LayoutManager
    • layoutContainer

      public void layoutContainer(Container target)
      Lays out the container. This method lets each visible component take its preferred size by reshaping the components in the target container in order to satisfy the alignment of this VerticalFlowLayout object.
      Specified by:
      layoutContainer in interface LayoutManager
      Parameters:
      target - the specified component being laid out
      See Also:
    • toString

      public String toString()
      Returns a string representation of this VerticalFlowLayout object and its values.
      Overrides:
      toString in class Object
      Returns:
      a string representation of this layout
    • main

      public static void main(String[] args)