LayoutManager2
Home ] Up ] FlowLayout ] LayoutManager ] [ LayoutManager2 ] Components & Containers ] BorderLayout ] GridLayout ] Insets ] Nested Layouts ]

 

 

The LayoutManager2 Interface

Some layout managers attach constraints to components that determine how the components are to be laid out.  As we'll see soon, BorderLayout is an example of such a layout manager.  

The LayoutManager2 interface is for such constraint-applying layout managers;  it extends from the LayoutManager interface, and adds the following methods:

Method Description
public void addLayoutComponent(Component comp, 
                               Object constraints)
Adds the specified component to the layout, using the specified constraint object.
public Dimension maximumLayoutSize(Container target)
Returns the maximum size of this component.
public float getLayoutAlignmentX(Container target)
Returns the alignment along the x axis. This specifies how the component would like to be aligned relative to other components. The value should be a number between 0 and 1 where 0 represents alignment along the origin, 1 is aligned the furthest away from the origin, 0.5 is centered, etc.
public float getLayoutAlignmentY(Container target)
Returns the alignment along the y axis. This specifies how the component would like to be aligned relative to other components. The value should be a number between 0 and 1 where 0 represents alignment along the origin, 1 is aligned the furthest away from the origin, 0.5 is centered, etc.
public void invalidateLayout(Container target)
Invalidates the layout, indicating that if the layout manager has cached information it should be discarded.

The BorderLayout, BoxLayout, CardLayout, and GridBagLayout layout managers all implement the LayoutManager2 interface.

 

This page was last modified on 02 October, 2007