java.awt.GridBagLayout (JDK 1.0)
This class implements the LayoutManager interface to lay out Component objects in a Container. It is the most complicated and most powerful LayoutManager in the java.awt package. It divides the container into a grid of rows and columns (which need not have the same width and height) and places the components into this grid, adjusting the size of the grid cells as necessary to ensure that components do not overlap. Each component controls how it is positioned within this grid by specifying a number of variables (or "constraints") in a GridBagConstraints object. Do not confuse this class with the much simpler GridLayout which arranges components in a grid of equally sized cells.
Use setConstraints() to specify a GridBagConstraints object for each of the components in the container. Or, in Java 1.1, specify the GridBagConstraints object when adding the component to the container with add(). The variables in this object specify the position of the component in the grid, the number of horizontal and vertical grid cells that the component occupies, and also control other important aspects of component layout. See GridBagConstraints for more information on these "constraint" variables. setConstraints() makes a copy of the constraints object, so you may reuse a single object in your code.
Note that applications should never call the LayoutManager methods of this class directly; the Container for which the GridBagLayout is registered does this.
public classGridBagLayoutextends Object implements LayoutManager2, Serializable { //Public ConstructorpublicGridBagLayout(); //Constantsprotected static final intMAXGRIDSIZE; protected static final intMINSIZE; protected static final intPREFERREDSIZE; //Public Instance Variablespublic double[]columnWeights; public int[]columnWidths; public int[]rowHeights; public double[]rowWeights; //Protected Instance Variablesprotected Hashtablecomptable; protected GridBagConstraintsdefaultConstraints; protected GridBagLayoutInfolayoutInfo; //Public Instance Methodspublic voidaddLayoutComponent(Stringname, Componentcomp); //From LayoutManager1.1 public voidaddLayoutComponent(Componentcomp, Objectconstraints); //From LayoutManager2public GridBagConstraintsgetConstraints(Componentcomp); 1.1 public floatgetLayoutAlignmentX(Containerparent); //From LayoutManager21.1 public floatgetLayoutAlignmentY(Containerparent); //From LayoutManager2public int[][]getLayoutDimensions(); public PointgetLayoutOrigin(); public double[][]getLayoutWeights(); 1.1 public voidinvalidateLayout(Containertarget); //From LayoutManager2public voidlayoutContainer(Containerparent); //From LayoutManagerpublic Pointlocation(intx, inty); 1.1 public DimensionmaximumLayoutSize(Containertarget); //From LayoutManager2public DimensionminimumLayoutSize(Containerparent); //From LayoutManagerpublic DimensionpreferredLayoutSize(Containerparent); //From LayoutManagerpublic voidremoveLayoutComponent(Componentcomp); //From LayoutManagerpublic voidsetConstraints(Componentcomp, GridBagConstraintsconstraints); public StringtoString(); //Overrides Object//Protected Instance Methodsprotected voidAdjustForGravity(GridBagConstraintsconstraints, Rectangler); protected voidArrangeGrid(Containerparent); protected GridBagLayoutInfoGetLayoutInfo(Containerparent, intsizeflag); protected DimensionGetMinSize(Containerparent, GridBagLayoutInfoinfo); protected GridBagConstraintslookupConstraints(Componentcomp); }
Hierarchy:
Object->GridBagLayout(LayoutManager2(LayoutManager), Serializable)