public class GridBag
extends java.awt.GridBagConstraints
// First, configure default for every or a specific column:
GridBag bag = new GridBag()
.setDefaultAnchor(0, GridBagConstraints.EAST)
.setDefaultAnchor(1, GridBagConstraints.WEST)
.setDefaultWeightX(1, 1)
.setDefaultFill(GridBagConstraints.HORIZONTAL);
// Then, add components to a panel:
// The following code adds a new line with 2 components with default settings:
panel.add(c1, bag.nextLine().next())
panel.add(c1, bag.next())
// The following code adds a component on the next line that covers all remaining columns:
panel.add(c1, bag.nextLine().coverLine())
// The following code adds a component on the next line with overridden settings:
panel.add(c1, bag.nextLine().next().insets(...).weightx(...))
// You also can pre-configure the object and pass it as a constraint:
bag.nextLine().next();
panel.add(c1, bag)
Note that every call of nextLine()
or next()
resets settings to the defaults for the corresponding column.ABOVE_BASELINE, ABOVE_BASELINE_LEADING, ABOVE_BASELINE_TRAILING, anchor, BASELINE, BASELINE_LEADING, BASELINE_TRAILING, BELOW_BASELINE, BELOW_BASELINE_LEADING, BELOW_BASELINE_TRAILING, BOTH, CENTER, EAST, fill, FIRST_LINE_END, FIRST_LINE_START, gridheight, gridwidth, gridx, gridy, HORIZONTAL, insets, ipadx, ipady, LAST_LINE_END, LAST_LINE_START, LINE_END, LINE_START, NONE, NORTH, NORTHEAST, NORTHWEST, PAGE_END, PAGE_START, RELATIVE, REMAINDER, SOUTH, SOUTHEAST, SOUTHWEST, VERTICAL, weightx, weighty, WEST
Constructor and Description |
---|
GridBag() |
public GridBag nextLine()
public GridBag next()
public int getLine()
public GridBag setLine(int line)
public int getColumn()
public GridBag setColumn(int cell)
public GridBag reset()
public GridBag anchor(int anchor)
public GridBag fillCell()
public GridBag fillCellHorizontally()
public GridBag fillCellVertically()
public GridBag fillCellNone()
public GridBag weightx(double weight)
public GridBag weighty(double weight)
public GridBag coverLine()
public GridBag coverLine(int cells)
public GridBag coverColumn()
public GridBag coverColumn(int cells)
public GridBag padx(int padding)
public GridBag pady(int padding)
public GridBag insets(int top, int left, int bottom, int right)
insets(java.awt.Insets)
public GridBag insetTop(int top)
public GridBag insetBottom(int bottom)
public GridBag insetLeft(int left)
public GridBag insetRight(int right)
public GridBag insets(java.awt.Insets insets)
public int getDefaultAnchor()
public GridBag setDefaultAnchor(int anchor)
public int getDefaultAnchor(int column)
public GridBag setDefaultAnchor(int column, int anchor)
public int getDefaultFill()
public GridBag setDefaultFill(int fill)
public int getDefaultFill(int column)
public GridBag setDefaultFill(int column, int fill)
public double getDefaultWeightX()
public GridBag setDefaultWeightX(double weight)
public double getDefaultWeightX(int column)
public GridBag setDefaultWeightX(int column, double weight)
public double getDefaultWeightY()
public GridBag setDefaultWeightY(double weight)
public double getDefaultWeightY(int column)
public GridBag setDefaultWeightY(int column, double weight)
public int getDefaultPaddingX()
public GridBag setDefaultPaddingX(int padding)
public int getDefaultPaddingX(int column)
public GridBag setDefaultPaddingX(int column, int padding)
public int getDefaultPaddingY()
public GridBag setDefaultPaddingY(int padding)
public int getDefaultPaddingY(int column)
public GridBag setDefaultPaddingY(int column, int padding)
public java.awt.Insets getDefaultInsets()
public GridBag setDefaultInsets(int top, int left, int bottom, int right)
public GridBag setDefaultInsets(java.awt.Insets insets)
public java.awt.Insets getDefaultInsets(int column)
public GridBag setDefaultInsets(int column, int top, int left, int bottom, int right)
public GridBag setDefaultInsets(int column, java.awt.Insets insets)