All About Class GridBagLayout in AWT in Java

GridBagLayout in AWT in Java

GridBagLayout in AWT in Java:

This is an upgraded version of GridLayout.GridBagLayout implements the LayoutManager interface to lay out Component objects in a Container. It is the most powerful LayoutManager. With this, we can specify the width, height of the individual grids in a container. The GridBagLayout manager is a flexible layout manager which aligns components horizontally and vertically, without requiring the component to be of the same size. Each GridBagLayout manager uses a rectangular grid of cells, with each component occupying one or more cells(display area). Each component in a GridBagLayout is associated with a set of constraints contained within a GridBagConstraints, instance contained within a GridBagConstraints, an instance that specifies how the component is to be laid out within its display area. The manner in which the GridBagLayout manager places a set of components depends on each components constraints and it's minimum size as well as the preferred size of the component's container. IIt ensures that components do not overlap by adjusting the size of the cells. To use a GridBagLayout effectively, one or more components must have customized GridBagConstraints objects created for it.
The class structure of GridBagLayout is given as:

public class java.awt.GridBagLayout extends java.lang.Object 
                                    implements java.awt.LayoutManager2,
//member elements 
protected final static int MAXGRIDSIZE;
//MAXGRIDSIZE is 128 the maximum number of grid position both horizontally and vertically that 
//can be laid out by GridBagLayout .
protected final static int MINSIZE;
//MINSIZE is 1.The smallest grid that can be laid out by GridBagLayout .
protected final static int PREFERREDSIZE;
public double[] columnWeights;
public int[] columnWidths;
public int[] rowHeights;
public double[] rowWeights;
protected Hashtable comptable;
protected GridBagConstraints defaultConstraints;
protected GridBagLayoutInfo layoutInfo;
public GridBagLayout();//creates a GridBagLayout manager
public void addLayoutComponent(String name,Component comp);
pulic void addLayoutComponent(Component comp,Object constraints);
public GridBagConstraints getConstraints(Component comp);
public void layoutContainer(Container target);
public float getLayoutAignmentX(Container target);
public float getLayoutAignmentY(Container target);
public Dimension minimumLayoutSize(Container target);
public Dimension preferredLayoutSize(Container target);
public void removeLayoutComponent(Component comp);
public void setConstraints(Component comp,GridBagConstraints constraints);
public int[][] getLayoutDimensions();
public Point getLayoutOrigin();
public double[][] getLayoutWeights();
public void invalidateLayout(Container target);
public Point location(int x,int y);
public Dimension maximumLayoutSize(Container target);
public String toString();
protected GridBagConstraints lookupConstraints(Component comp);
protected void adjustForGravity(GridBagConstraints constraints,Rectangle rec);
protected void arrangeGrid(Container target);
protected GridBagLayoutInfo getLayoutInfo(Container target,int sizeflag);
protected Dimension getMinSize(Container target,GridBagLayoutInfo info);
All About Class GridBagLayout in AWT in Java All About Class GridBagLayout in AWT in Java Reviewed by Animesh Chatterjee on October 23, 2018 Rating: 5

No comments:

Powered by Blogger.