Class RiverLayout

java.lang.Object
java.awt.FlowLayout
se.datadosen.component.RiverLayout
All Implemented Interfaces:
java.awt.LayoutManager, java.io.Serializable

public class RiverLayout
extends java.awt.FlowLayout
implements java.awt.LayoutManager, java.io.Serializable

RiverLayout makes it very simple to construct user interfaces as components are laid out similar to how text is added to a word processor (Components flow like a "river". RiverLayout is however much more powerful than FlowLayout: Components added with the add() method generally gets laid out horizontally, but one may add a string before the component being added to specify "constraints" like this: add("br hfill", new JTextField("Your name here"); The code above forces a "line break" and extends the added component horizontally. Without the "hfill" constraint, the component would take on its preferred size.


List of constraints:
  • br - Add a line break
  • p - Add a paragraph break
  • tab - Add a tab stop (handy for constructing forms with labels followed by fields)
  • hfill - Extend component horizontally
  • vfill - Extent component vertically (only one line allowed per container) //$rh
  • left - Align following components to the left (default)
  • center - Align following components horizontally centered
  • right - Align following components to the right
  • vtop - Align following components vertically top aligned
  • vcenter - Align following components vertically centered (default)
RiverLayout is LGPL licenced - use it freely in free and commercial programs
See Also:
Serialized Form
  • Field Summary

    Fields 
    Modifier and Type Field Description
    static java.lang.String CENTER  
    static java.lang.String HFILL  
    static java.lang.String LABEL  
    static java.lang.String LEFT  
    static java.lang.String LINE_BREAK  
    static java.lang.String PARAGRAPH_BREAK  
    static java.lang.String RIGHT  
    static java.lang.String TAB_STOP  
    static java.lang.String VBOTTOM  
    static java.lang.String VCENTER  
    static java.lang.String VFILL  
    static java.lang.String VTOP  

    Fields inherited from class java.awt.FlowLayout

    LEADING, TRAILING
  • Constructor Summary

    Constructors 
    Constructor Description
    RiverLayout()  
    RiverLayout​(int hgap, int vgap)  
  • Method Summary

    Modifier and Type Method Description
    void addLayoutComponent​(java.lang.String name, java.awt.Component comp)  
    protected void adjustAlignment​(java.awt.Component m)  
    protected se.datadosen.component.Ruler calcTabs​(java.awt.Container target)
    Figure out tab stop x-positions
    java.awt.Insets getExtraInsets()
    Gets the extra insets of all the components in the container.
    int getHgap()
    Gets the horizontal gap between components.
    protected java.awt.Insets getInsets​(java.awt.Container target)  
    int getVgap()
    Gets the vertical gap between components.
    void layoutContainer​(java.awt.Container target)
    Lays out the container.
    java.awt.Dimension minimumLayoutSize​(java.awt.Container target)
    Returns the minimum dimensions needed to layout the visible components contained in the specified target container.
    protected void moveComponents​(java.awt.Container target, int x, int y, int width, int height, int rowStart, int rowEnd, boolean ltr, se.datadosen.component.Ruler ruler)
    Centers the elements in the specified row, if there is any slack.
    java.awt.Dimension preferredLayoutSize​(java.awt.Container target)
    Returns the preferred dimensions for this layout given the visible components in the specified target container.
    protected void relMove​(java.awt.Container target, int dx, int dy, int rowStart, int rowEnd)  
    void removeLayoutComponent​(java.awt.Component comp)
    Removes the specified component from the layout.
    void setExtraInsets​(java.awt.Insets newExtraInsets)
    Set the extra insets of all the components in the container.
    void setHgap​(int hgap)
    Sets the horizontal gap between components.
    void setVgap​(int vgap)
    Sets the vertical gap between components.

    Methods inherited from class java.awt.FlowLayout

    getAlignment, getAlignOnBaseline, setAlignment, setAlignOnBaseline, toString

    Methods inherited from class java.lang.Object

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

  • Constructor Details

  • Method Details

    • getHgap

      public int getHgap()
      Gets the horizontal gap between components.
      Overrides:
      getHgap in class java.awt.FlowLayout
    • setHgap

      public void setHgap​(int hgap)
      Sets the horizontal gap between components.
      Overrides:
      setHgap in class java.awt.FlowLayout
    • getVgap

      public int getVgap()
      Gets the vertical gap between components.
      Overrides:
      getVgap in class java.awt.FlowLayout
    • getExtraInsets

      public java.awt.Insets getExtraInsets()
      Gets the extra insets of all the components in the container.
    • setExtraInsets

      public void setExtraInsets​(java.awt.Insets newExtraInsets)
      Set the extra insets of all the components in the container.
    • getInsets

      protected java.awt.Insets getInsets​(java.awt.Container target)
    • setVgap

      public void setVgap​(int vgap)
      Sets the vertical gap between components.
      Overrides:
      setVgap in class java.awt.FlowLayout
    • addLayoutComponent

      public void addLayoutComponent​(java.lang.String name, java.awt.Component comp)
      Specified by:
      addLayoutComponent in interface java.awt.LayoutManager
      Overrides:
      addLayoutComponent in class java.awt.FlowLayout
      Parameters:
      name - the name of the component
      comp - the component to be added
    • removeLayoutComponent

      public void removeLayoutComponent​(java.awt.Component comp)
      Removes the specified component from the layout. Not used by this class.
      Specified by:
      removeLayoutComponent in interface java.awt.LayoutManager
      Overrides:
      removeLayoutComponent in class java.awt.FlowLayout
      Parameters:
      comp - the component to remove
      See Also:
      Container.removeAll()
    • calcTabs

      protected se.datadosen.component.Ruler calcTabs​(java.awt.Container target)
      Figure out tab stop x-positions
    • preferredLayoutSize

      public java.awt.Dimension preferredLayoutSize​(java.awt.Container target)
      Returns the preferred dimensions for this layout given the visible components in the specified target container.
      Specified by:
      preferredLayoutSize in interface java.awt.LayoutManager
      Overrides:
      preferredLayoutSize in class java.awt.FlowLayout
      Parameters:
      target - the component which needs to be laid out
      Returns:
      the preferred dimensions to lay out the subcomponents of the specified container
      See Also:
      Container, minimumLayoutSize(java.awt.Container), Container.getPreferredSize()
    • minimumLayoutSize

      public java.awt.Dimension minimumLayoutSize​(java.awt.Container target)
      Returns the minimum dimensions needed to layout the visible components contained in the specified target container.
      Specified by:
      minimumLayoutSize in interface java.awt.LayoutManager
      Overrides:
      minimumLayoutSize in class java.awt.FlowLayout
      Parameters:
      target - the component which needs to be laid out
      Returns:
      the minimum dimensions to lay out the subcomponents of the specified container
      See Also:
      preferredLayoutSize(java.awt.Container), Container, Container.doLayout()
    • moveComponents

      protected void moveComponents​(java.awt.Container target, int x, int y, int width, int height, int rowStart, int rowEnd, boolean ltr, se.datadosen.component.Ruler ruler)
      Centers the elements in the specified row, if there is any slack.
      Parameters:
      target - the component which needs to be moved
      x - the x coordinate
      y - the y coordinate
      width - the width dimensions
      height - the height dimensions
      rowStart - the beginning of the row
      rowEnd - the the ending of the row
    • relMove

      protected void relMove​(java.awt.Container target, int dx, int dy, int rowStart, int rowEnd)
    • adjustAlignment

      protected void adjustAlignment​(java.awt.Component m)
    • layoutContainer

      public void layoutContainer​(java.awt.Container target)
      Lays out the container. This method lets each component take its preferred size by reshaping the components in the target container in order to satisfy the constraints of this FlowLayout object.
      Specified by:
      layoutContainer in interface java.awt.LayoutManager
      Overrides:
      layoutContainer in class java.awt.FlowLayout
      Parameters:
      target - the specified component being laid out
      See Also:
      Container, Container.doLayout()