Class sunsoft.jws.visual.rt.awt.GBLayout
All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class sunsoft.jws.visual.rt.awt.GBLayout

java.lang.Object
   |
   +----sunsoft.jws.visual.rt.awt.GBLayout

public class GBLayout
extends Object
implements LayoutManager
GBLayout is a flexible layout manager that aligns components vertically and horizontally, without requiring that the components be the same size. Each GBLayout uses a rectangular grid of cells, with each component occupying one or more cells (called its display area). Each component managed by a GBLayout is associated with a GBConstraints instance that specifies how the component is laid out within its display area. How a GBLayout places a set of components depends on each component's GBConstraints and minimum size, as well as the preferred size of the components' container.

To use a GBLayout effectively, you must customize one or more of its components' GBConstraints. You customize a GBConstraints object by setting one or more of its instance variables:

gridx, gridy
Specifies the cell at the upper left of the component's display area, where the upper-left-most cell has address gridx=0, gridy=0. Use GBConstraints.RELATIVE (the default value) to specify that the component be just placed just to the right of (for gridx) or just below (for gridy) the component that was added to the container just before this component was added.
gridwidth, gridheight
Specifies the number of cells in a row (for gridwidth) or column (for gridheight) in the component's display area. The default value is 1. Use GBConstraints.REMAINDER to specify that the component be the last one in its row (for gridwidth) or column (for gridheight). Use GBConstraints.RELATIVE to specify that the component be the next to last one in its row (for gridwidth) or column (for gridheight).
fill
Used when the component's display area is larger than the component's requested size to determine whether (and how) to resize the component. Valid values are GBConstraints.NONE (the default), GBConstraints.HORIZONTAL (make the component wide enough to fill its display area horizontally, but don't change its height), GBConstraints.VERTICAL (make the component tall enough to fill its display area vertically, but don't change its width), and GBConstraints.BOTH (make the component fill its display area entirely).
ipadx, ipady
Specifies the internal padding: how much to add to the minimum size of the component. The width of the component will be at least its minimum width plus ipadx*2 pixels (since the padding applies to both sides of the component). Similarly, the height of the component will be at least the minimum height plus ipady*2 pixels.
insets
Specifies the external padding of the component -- the minimum amount of space between the component and the edges of its display area.
anchor
Used when the component is smaller than its display area to determine where (within the area) to place the component. Valid values are GBConstraints.CENTER (the default), GBConstraints.NORTH, GBConstraints.NORTHEAST, GBConstraints.EAST, GBConstraints.SOUTHEAST, GBConstraints.SOUTH, GBConstraints.SOUTHWEST, GBConstraints.WEST, and GBConstraints.NORTHWEST.
weightx, weighty
Used to determine how to distribute space; this is important for specifying resizing behavior. Unless you specify a weight for at least one component in a row (weightx) and column (weighty), all the components clump together in the center of their container. This is because when the weight is zero (the default), the GBLayout puts any extra space between its grid of cells and the edges of the container.
The following figure shows ten components (all buttons) managed by a GBLayout:
All the components have fill=GBConstraints.BOTH. In addition, the components have the following non-default constraints: Here is the code that implements the example shown above:
import java.awt.*;
import java.util.*;
import java.applet.Applet;
public class GridBagEx1 extends Applet {
    protected void makebutton(String name,
                              GBLayout gridbag,
                              GBConstraints c) {
        Button button = new Button(name);
        gridbag.setConstraints(button, c);
        add(button);
    }
    public void init() {
        GBLayout gridbag = new GBLayout();
        GBConstraints c = new GBConstraints();
        setFont(new Font("Helvetica", Font.PLAIN, 14));
        setLayout(gridbag);
        c.fill = GBConstraints.BOTH;
        c.weightx = 1.0;
        makebutton("Button1", gridbag, c);
        makebutton("Button2", gridbag, c);
        makebutton("Button3", gridbag, c);
	c.gridwidth = GBConstraints.REMAINDER; //end row
        makebutton("Button4", gridbag, c);
        c.weightx = 0.0;		   //reset to the default
        makebutton("Button5", gridbag, c); //another row
	c.gridwidth = GBConstraints.RELATIVE; //next-to-last in row
        makebutton("Button6", gridbag, c);
	c.gridwidth = GBConstraints.REMAINDER; //end row
        makebutton("Button7", gridbag, c);
	c.gridwidth = 1;	   	   //reset to the default
	c.gridheight = 2;
        c.weighty = 1.0;
        makebutton("Button8", gridbag, c);
        c.weighty = 0.0;		   //reset to the default
	c.gridwidth = GBConstraints.REMAINDER; //end row
	c.gridheight = 1;		   //reset to the default
        makebutton("Button9", gridbag, c);
        makebutton("Button10", gridbag, c);
        resize(300, 100);
    }
    public static void main(String args[]) {
	Frame f = new Frame("GridBag Layout Example");
	GridBagEx1 ex1 = new GridBagEx1();
	ex1.init();
	f.add("Center", ex1);
	f.pack();
	f.resize(f.preferredSize());
	f.show();
    }
}
    

Variable Index

 o anchor
 o clipAnchor
 o columnWeights
Determines the minimum weights for the grid columns.
 o columnWidths
Determines the minimum widths for the grid columns.
 o comptable
 o defaultConstraints
 o INITGRIDSIZE
 o layoutInfo
 o MINSIZE
 o PREFERREDSIZE
 o rowHeights
Determines the minimum heights for the grid rows.
 o rowWeights
Determines the minimum weights for the grid rows.
 o TINYSIZE

Constructor Index

 o GBLayout()
Creates a gridbag layout.

Method Index

 o addLayoutComponent(String, Component)
Adds the specified component with the specified name to the layout.
 o AdjustForGravity(GBConstraints, Rectangle)
Adjusts the x, y, width, and height fields to the correct values according to the constraint geometry and pads.
 o ArrangeGrid(Container)
Lays out the grid.
 o ArrangeGrid(Container, boolean)
Lays out the grid, conditionally reshaping the children.
 o disable()
Globally disable gridbag layout.
 o enable()
Globally enable gridbag layout.
 o getAnchor()
Returns the current anchor.
 o getClipAnchor()
Returns the current clip anchor.
 o getConstraints(Component)
Retrieves the constraints for the specified component.
 o getLayoutDimensions()
Returns the widths and heights of the grid columns and rows.
 o GetLayoutInfo(Container, int)
Fill in an instance of the GBLayoutInfo structure for the current set of managed children.
 o getLayoutOrigin()
Returns the coordinates of the upper-left corner of the grid.
 o getLayoutWeights()
Returns the current set of weights for the grid columns and rows.
 o getMinimumLayoutDimensions(Container)
Returns the minimum widths and heights of the grid columns and rows.
 o GetMinSize(Container, GBLayoutInfo)
Figure out the minimum size of the parent based on the information retrieved from GetLayoutInfo.
 o getPreferredLayoutDimensions(Container)
Returns the preferred widths and heights of the grid columns and rows.
 o layoutContainer(Container)
Lays out the container in the specified panel.
 o layoutContainerNoReshape(Container)
Does everything that layout normally does, except the components aren't actually reshaped.
 o location(int, int)
Returns the coordinates of the grid cell corresponding to the given pixel coordinates.
 o lookupConstraints(Component)
Retrieves the constraints for the specified component.
 o minimumLayoutSize(Container)
Returns the minimum dimensions needed to layout the components contained in the specified panel.
 o preferredLayoutSize(Container)
Returns the preferred dimensions for this layout given the components in the specified panel.
 o removeLayoutComponent(Component)
Removes the specified component from the layout.
 o setAnchor(int)
Sets the anchor for the gridbag.
 o setClipAnchor(int)
Sets the clip anchor.
 o setConstraints(Component, GBConstraints)
Sets the constraints for the specified component.
 o setConstraints(Component, String)
Sets the constraints from an option string.
 o tinyLayoutSize(Container)
Returns the smallest allowable size for the specified panel.
 o toString()
Returns the String representation of this GBLayout's values.

Variables

 o columnWidths
  public int columnWidths[]
Determines the minimum widths for the grid columns.
 o rowHeights
  public int rowHeights[]
Determines the minimum heights for the grid rows.
 o columnWeights
  public double columnWeights[]
Determines the minimum weights for the grid columns.
 o rowWeights
  public double rowWeights[]
Determines the minimum weights for the grid rows.
 o INITGRIDSIZE
  protected final static int INITGRIDSIZE
 o MINSIZE
  protected final static int MINSIZE
 o PREFERREDSIZE
  protected final static int PREFERREDSIZE
 o TINYSIZE
  protected final static int TINYSIZE
 o comptable
  protected Hashtable comptable
 o defaultConstraints
  protected GBConstraints defaultConstraints
 o layoutInfo
  protected GBLayoutInfo layoutInfo
 o anchor
  protected int anchor
 o clipAnchor
  protected int clipAnchor

Constructors

 o GBLayout
  public GBLayout()
Creates a gridbag layout.

Methods

 o enable
  public static synchronized void enable()
Globally enable gridbag layout. The default is for gridbag layout to be enabled.
 o disable
  public static synchronized void disable()
Globally disable gridbag layout. This can be used to improve performance by temporarily disabling layout during spurious calls to validate.
 o setConstraints
  public void setConstraints(Component comp,
                             GBConstraints constraints)
Sets the constraints for the specified component.
Parameters:
comp - the component to be modified
constraints - the constraints to be applied
 o setConstraints
  public void setConstraints(Component comp,
                             String constraints)
Sets the constraints from an option string. Each option has the form key=value. Options are separated by semicolons (;).
Parameters:
comp - the component to be modified
constraints - the constraints string
 o getConstraints
  public GBConstraints getConstraints(Component comp)
Retrieves the constraints for the specified component. A copy of the constraints is returned.
Parameters:
comp - the component to be queried
 o lookupConstraints
  protected GBConstraints lookupConstraints(Component comp)
Retrieves the constraints for the specified component. The return value is not a copy, but is the actual constraints class used by the layout mechanism.
Parameters:
comp - the component to be queried
 o getLayoutOrigin
  public Point getLayoutOrigin()
Returns the coordinates of the upper-left corner of the grid. The coordinates are based on the current layout of the grid.
 o getLayoutDimensions
  public int[][] getLayoutDimensions()
Returns the widths and heights of the grid columns and rows. The dimensions are based on the current layout of the grid.
 o getMinimumLayoutDimensions
  public int[][] getMinimumLayoutDimensions(Container parent)
Returns the minimum widths and heights of the grid columns and rows. This is how the grid would be arranged if the parent were to be reshaped to its minimum size.
 o getPreferredLayoutDimensions
  public int[][] getPreferredLayoutDimensions(Container parent)
Returns the preferred widths and heights of the grid columns and rows. This is how the grid would be arranged if the parent were to be reshaped to its preferred size.
 o getLayoutWeights
  public double[][] getLayoutWeights()
Returns the current set of weights for the grid columns and rows. The return value reflects the effective weights for the columns and rows after taking into account the weight constraints that are set on the child components.
 o location
  public Point location(int x,
                        int y)
Returns the coordinates of the grid cell corresponding to the given pixel coordinates.
 o setAnchor
  public void setAnchor(int anchor)
Sets the anchor for the gridbag. The anchor determines the placement for the child components when the container has extra space and none of the children have weights. The default anchor is CENTER.
 o getAnchor
  public int getAnchor()
Returns the current anchor.
 o setClipAnchor
  public void setClipAnchor(int clipAnchor)
Sets the clip anchor. The clip anchor determines which edge(s) of the container get clipped when there is not enough space. The default clip anchor is NORTHWEST. A clip anchor of NORTHWEST means that northwest corner is anchored, so the south and east edges will be clipped if there is not enough space.
 o getClipAnchor
  public int getClipAnchor()
Returns the current clip anchor.
 o addLayoutComponent
  public void addLayoutComponent(String name,
                                 Component comp)
Adds the specified component with the specified name to the layout. The name is converted to a set of GBConstraints.
Parameters:
name - the constraints string
comp - the component to be added
 o removeLayoutComponent
  public void removeLayoutComponent(Component comp)
Removes the specified component from the layout. Does not apply.
Parameters:
comp - the component to be removed
 o preferredLayoutSize
  public Dimension preferredLayoutSize(Container parent)
Returns the preferred dimensions for this layout given the components in the specified panel.
Parameters:
parent - the component which needs to be laid out
See Also:
minimumLayoutSize
 o minimumLayoutSize
  public Dimension minimumLayoutSize(Container parent)
Returns the minimum dimensions needed to layout the components contained in the specified panel.
Parameters:
parent - the component which needs to be laid out
See Also:
preferredLayoutSize
 o tinyLayoutSize
  public Dimension tinyLayoutSize(Container parent)
Returns the smallest allowable size for the specified panel. This can be smaller than minimumSize if there are insets and pads set on any of the panel's children.
Parameters:
parent - the component which needs to be laid out
See Also:
preferredLayoutSize
 o layoutContainer
  public void layoutContainer(Container parent)
Lays out the container in the specified panel.
Parameters:
parent - the specified component being laid out
See Also:
Container
 o layoutContainerNoReshape
  public void layoutContainerNoReshape(Container parent)
Does everything that layout normally does, except the components aren't actually reshaped. This has the useful side effect of setting the location and size variables in the constraints for each component.
Parameters:
parent - the specified component being laid out
See Also:
Container
 o toString
  public String toString()
Returns the String representation of this GBLayout's values.
Overrides:
toString in class Object
 o GetLayoutInfo
  protected GBLayoutInfo GetLayoutInfo(Container parent,
                                       int sizeflag)
Fill in an instance of the GBLayoutInfo structure for the current set of managed children. This requires four passes through the child components:
1) Figure out the dimensions of the layout grid.
2) Determine which cells the components occupy.
3) Distribute the weights among the rows/columns.
4) Distribute the minimum sizes among the rows/columns.
This also caches the minsizes for all the children when they are first encountered (so subsequent loops don't need to ask again).
 o AdjustForGravity
  protected void AdjustForGravity(GBConstraints c,
                                  Rectangle r)
Adjusts the x, y, width, and height fields to the correct values according to the constraint geometry and pads.
 o GetMinSize
  protected Dimension GetMinSize(Container parent,
                                 GBLayoutInfo info)
Figure out the minimum size of the parent based on the information retrieved from GetLayoutInfo.
 o ArrangeGrid
  protected void ArrangeGrid(Container parent)
Lays out the grid. Called directly from layoutContainer.
 o ArrangeGrid
  protected void ArrangeGrid(Container parent,
                             boolean doReshape)
Lays out the grid, conditionally reshaping the children. The doReshape flag indicates whether or not the children should be reshaped.
See Also:
layoutContainerNoReshape

All Packages  Class Hierarchy  This Package  Previous  Next  Index