Abstract Interface LayoutManager2 in Java

0
17
Spread the love
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
    165
    Shares

Abstract interface LayoutManager2 in Java

LayoutManager2 interface is an extension of the LayoutManager interface. It defines additional layout management methods for layout managers that perform constraint-based layout.

It provides a more generalized way to add components to a container, as well as more sizing and alignment methods.

GridBagLayout is an example of a constraint-based layout manager – each component added to the layout is associated with a GridBagConstraints object that specifies the constraints ” on how the component is to be laid out.

Java programs do not directly invoke the methods of this interface – – they are used by the Container object for which the layout manager is registered.

public abstract interface java.awt.LayoutManager2 extends java.awt.LayoutManager (
// Public Instance 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);
}

The details of the class structure are given as follows:

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

public abstract void addLayoutComponent (Component comp,Object constraints) method adds an object to a container.This is slightly more generic than LayoutManager’s addLayoutComponent(String, Component).

Parameter
comp – Component to add.
constraints – Constraints on the component.

public abstract float getLayoutAlignmentX(Container target);

public abstract float getLayoutAlignmentX(Container target) 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.

This method returns a value between 0 and 1.

Parameter
target – The container to inspect.

public abstract float getLayoutAlignmentY(Container target);

public abstract float getLayoutAlignmentY(Container target) 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.

This method returns a value between 0 and 1.

Parameter
target – The container to inspect.

public abstract void invalidateLayout(Container target);

public abstract void invalidateLayout(Container target) method can be used to signal the manager to discard any cached information and start fresh. This method may cache information to improve performance

Parameter
target – The container to invalidate.

public abstract Dimension maximumLayoutSize(Container target);

public abstract Dimension maximumLayoutSize(Container target) method returns the maximum size of target using this layout manager.

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

Parameter
target – The container to inspect.

Don't miss out!
Subscribe To Newsletter

Receive top technical news, lesson ideas, travel tips and more!

Invalid email address
Give it a try. You can unsubscribe at any time.

Spread the love
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
    165
    Shares

LEAVE A REPLY

Please enter your comment!
Please enter your name here