[Chapter 19] LayoutManager2

#

| Chapter 19 java.awt Reference |

# LayoutManager2

## Name

LayoutManager2

##

## Description

`LayoutManager2` is an extension of `LayoutManager`. It provides a more generalized way to add components to a container, as well as more sizing and alignment methods.

## Interface Definition

    public abstract interface java.awt.LayoutManager2
        extends java.awt.LayoutManager {

      // Interface Methods
      public abstract void addLayoutComponent (Component comp,
          Object constraints);
      public abstract float getLayoutAlignmentX(Container target);
      public abstract float getLayoutAlignmentY(Container target);
      public abstract void invalidateLayout(Container target);
      public abstract Dimension maximumLayoutSize(Container target);
    }

## Interface Methods

### addLayoutComponent

#### public abstract void addLayoutComponent (Component comp, Object constraints)

Parameters

  comp

    Component to add.

  constraints

    Constraints on the component.

Description

  Called to add an object to a container. This is slightly more generic than `LayoutManager`'s `addLayoutComponent(String, Component)`.

### getLayoutAlignmentX

#### public abstract float getLayoutAlignmentX (Container target)

Parameters

  target

    The container to inspect.

Returns

  A value between 0 and 1.

Description

  This method returns the preferred alignment of the given container `target`. A return value of 0 is left aligned, .5 is centered, and 1 is right aligned.

### getLayoutAlignmentY

#### public abstract float getLayoutAlignmentY (Container target)

Parameters

  target

    The container to inspect.

Returns

  A value between 0 and 1.

Description

  This method returns the preferred alignment of the given container `target`. A return value of 0 is top aligned, .5 is centered, and 1 is bottom aligned.

### invalidateLayout

#### public abstract void invalidateLayout (Container target)

Parameters

  target

    The container to invalidate.

Description

  Sophisticated layout managers may cache information to improve performance. This method can be used to signal the manager to discard any cached information and start fresh.

### maximumLayoutSize

#### public abstract Dimension maximumLayoutSize (Container target)

Returns

  The maximum size of `target`.

Parameters

  target

    The container to inspect.

Description

  This method returns the maximum size of `target` using this layout manager.

## See Also

`BorderLayout`, `CardLayout`, `Component`, `Container`, `GridBagLayout`, `Object`, `String`

LayoutManager |  | List