All About Class GridBagConstraints in Java

0
67
Spread the love
  • 24
  • 34
  • 28
  • 35
  •  
  •  
  •  
  • 12
  •  
  •  
    133
    Shares

GridBagConstraints in Java
GridBagConstraints in Java

GridBagConstraints in Java:

The GridBagConstraints class specifies constraints for components that are laid out using GridBagLayout class. This class encapsulate the instance variables to guide GridBagLayout on how to position a given component within the Container.
The GridBagLayout is written here for reference.

The class structure of class GridBagConstraints is given as:


public class java.awt.GridBagConstraints extends java.lang.Object 
                                         implements java.lang.Cloneable,
                                         java.io.Serializable{
//member elements
public int anchor;
//This field is used when the component is smaller than its display area.
//It determines where,within the area, to place the component.
//Valid values are as follows:
public final static int CENTER;
public final static int EAST;
public final static int NORTH;
public final static int NORTHEAST;
public final static int NORTHWEST;
public final static int SOUTH;
public final static int SOUTHWEST;
public final static int SOUTHEAST;
public final static int WEST;
//The default value of GridBagConstraints is CENTER.
public int fill;
//The fill field has one of the following value:
public final static int BOTH;
public final static int HORIZONTAL;
public final static int NONE;
public final static int VERTICAL;
//The filed is used when component's display area is larger that component's
//requested size.It determines whether to resize the component and if so
//valid values are as follows:
GridBagConstraints.NONE;//do not resize the component.
GridBagConstraints.HORIZONTAL;//Make the component wide enough to fill its
//display area horizontally but do not change its height.
GridBagConstraints.VERTICAL;//Make the component lengthy enough to fill its
// display area vertically but do not change it's width.
GridBagConstraints.BOTH;//Make component fill its display area entierly.
//The default value is GridBagConstraints.NONE;
public int gridHeight;
//specifies the number of cells in a column for the component's display area.
//Use GridBagConstaints.REMAINDER to specify the component to be the last one
//in it's column.Use GridBagConstaints.RELATIVE to specify that
//the component be the next to last one it's column.The default is 1.
public int gridWidth;
//specifies the number of cells in a row for the component's display area.Use
// GridBagConstaints.REMAINDER to specify that the component be the last one in
// its row.Use GridBagConstaints.RELATIVE to spcify that the
//component be the next to the last one in its row.The default is 1.
public int gridx;
//Specifies the cell at the left of the component's display area,where the leftmost
// cell has gridx=0.The value GridBagConstaints.RELATIVE specifies that the component
//to be placed just to the right of the component that was added to the container just
// before this component was added.The default value is GridBagConstaints.RELATIVE.
public int gridy;
//Specifies the cell at the top of the component's display area,where the topmost cell
// has gridy=0.The value GridBagConstaints.RELATIVE specifies that the component to be
//placed just below the component that was added to the container just before this
//component was added.The default value is GridBagConstaints.RELATIVE.
//The possible values for gridHeight,gridWidth,gridx,gridy:
public final static int REMAINDER;
public final static int RELATIVE;
public Insets insets;
//this field specifies the extended padding of the component,the minimum amount of
//space between the component and the edge of it's display area.the default value
//is new Insets(0,0,0,0);
public int ipadx;
//This field specifies the internal padding that is how much space to add to the
//minimum size of the component.The width of the component is at least it's minimum
//width plus ipadx*2pixels.
//The default value is 0.
public int ipady;
//This field specifies the internal padding that is how much space to add to the
//minimum size of the component.The height of the component is at least it's minimum
// height plus ipady*2pixels.The default value is 0.
public double weightx;
//this field specifies how to distribute extra vertical space.The GridBagLayout manager
//calculates the weight of a row to be the maximum weightx of all the component in a
//row.If the resulting layout is smaller vertically than the area it needs to fill,the
//extra space is distributed to each row in proportion to its weight.A row which has
//wight 0 receives no extra space.If all the weights are zero,all the extra
// space appears between the grids of the cell and the top and bottom edge.The default
// value is zero(0).
public double weighty;
this field specifies how to distribute extra horizontal space.The GridBagLayout manager
// calculates the weight of a column to be the maximum weighty of all the component in
//a row.If the resulting layout is smaller horizontally than the area it needs to fill,
//the extra space is distributed to each column in proportion to its weight.A column which
// has weight 0 receives no extra space.If all the weights are zero,all the extra space
//appears between the grids of the cell and the left and right edge.The default value
//is zero(0).instance variable
//constructor
public GridBagConstaints();
//creates a GridBagConstaints object with all the fields set to their default value.
//method
public Object clone();
//returns a copy of this GridBagConstaints.
}
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
  • 24
  • 34
  • 28
  • 35
  •  
  •  
  •  
  • 12
  •  
  •  
    133
    Shares

LEAVE A REPLY

Please enter your comment!
Please enter your name here