public class Packer extends java.awt.GridBagLayout implements PackAs
Panel p = new Panel(); // Create new Panel container
Label l = new Label( "label: " ); // Create a label Component
TextField t = new TextField( 30 ); // Create a TextField Component
Packer pk = new Packer(p); // Create Layout and setLayout on container
pk.pack( l ).gridx(0); // Add to Container and layout
pk.pack( t ).gridx(1).fillx(); // Add to Container and layout
Pay attention to the fact that fillx(), filly() and fillboth() change the weights of the respective axis. This is done to unify the expansion factors to equally distribute the components if you do not specify weight[xy] values. If you do not specify the weight[xy] values, they default to 1. Thus, you must always put the weight[xy]() after the fill[xy]() if you want something different than equal expansion.
When putting several buttons into a JPanel, you can use
...fillx().weightx(0) to make all of them the same width,
but keep the JPanel from being any wider than the widest button.
| Modifier and Type | Field and Description |
|---|---|
protected java.awt.Component |
comp
The component currently being layed out.
|
protected java.awt.Container |
container
If the Packer( Container ) constructor is used, this
member contains a reference to the container that this
instance provides layout for.
|
protected java.awt.GridBagConstraints |
gc
The current constraints used for subsequent uses of the PackAs
interface returned by the methods below.
|
| Constructor and Description |
|---|
Packer()
Create a new Packer instance.
|
Packer(java.awt.Container cont)
Creates a new Packer instance that is used to layout the
passed container.
|
| Modifier and Type | Method and Description |
|---|---|
PackAs |
add(java.awt.Component cp)
Reuses the previous set of constraints to layout the widget passed
|
PackAs |
bottom()
Add gridheight=RELATIVE to the constraints for the current
component.
|
java.lang.Object |
clone()
Create a copy of this Packer Object.
|
PackAs |
east()
Add anchor=EAST to the constraints for the current
component.
|
PackAs |
fillboth()
Add fill=BOTH, weighty=1, weightx=1 to the constraints for the current
component.
|
PackAs |
fillx()
Add fill=HORIZONTAL, weightx=1 to the constraints for the current
component.
|
PackAs |
filly()
Add fill=VERTICAL, weighty=1 to the constraints for the current
component.
|
boolean |
getAnchorEast() |
boolean |
getAnchorNorth() |
boolean |
getAnchorNorthEast() |
boolean |
getAnchorNorthWest() |
boolean |
getAnchorSouth() |
boolean |
getAnchorSouthEast() |
boolean |
getAnchorSouthWest() |
boolean |
getAnchorWest() |
java.awt.Container |
getContainer()
Get the designated container for this instance.
|
boolean |
getFillBoth() |
boolean |
getFillX() |
boolean |
getFillY() |
int |
getGridH() |
int |
getGridW() |
int |
getGridX() |
int |
getGridY() |
int |
getInsetBottom() |
int |
getInsetLeft() |
int |
getInsetRight() |
int |
getInsetTop() |
int |
getPadX() |
int |
getPadY() |
boolean |
getRemainX() |
boolean |
getRemainY() |
double |
getWeightX() |
double |
getWeightY() |
boolean |
getXLeftRelative() |
boolean |
getXRightRelative() |
boolean |
getYBottomRelative() |
boolean |
getYTopRelative() |
PackAs |
gridh(int tot)
Add gridheight=tot to the constraints for the current
component.
|
PackAs |
gridw(int tot)
Add gridwidth=tot to the constraints for the current
component.
|
PackAs |
gridx(int tot)
Add gridx=tot to the constraints for the current
component.
|
PackAs |
gridy(int tot)
Add gridy=tot to the constraints for the current
component.
|
PackAs |
inset(java.awt.Insets insets)
Specify the insets for the component.
|
PackAs |
inset(int top,
int left,
int bottom,
int right)
Specify the insets for the component.
|
PackAs |
into(java.awt.Container cont)
This method is used to specify the container that the next component
that is added or packed will be placed in.
|
PackAs |
left()
Add gridx=RELATIVE to the constraints for the current
component.
|
PackAs |
north()
Add anchor=NORTH to the constraints for the current
component.
|
PackAs |
northeast()
Add anchor=NORTHEAST to the constraints for the current
component.
|
PackAs |
northwest()
Add anchor=NORTHWEST to the constraints for the current
component.
|
PackAs |
pack(java.awt.Component cp)
Establishes a new set of constraints to layout the widget passed.
|
PackAs |
padx(int cnt)
Add ipadx=cnt to the constraints for the current
component.
|
PackAs |
pady(int cnt)
Add ipady=cnt to the constraints for the current
component.
|
PackAs |
remainx()
Add gridwidth=REMAINDER to the constraints for the current
component.
|
PackAs |
remainy()
Add gridheight=REMAINDER to the constraints for the current
component.
|
PackAs |
right()
Add gridwidth=RELATIVE to the constraints for the current
component.
|
PackAs |
setAnchorEast(boolean how)
Add anchor=EAST to the constraints for the current
component if how == true remove it if false.
|
PackAs |
setAnchorNorth(boolean how)
Add anchor=NORTH to the constraints for the current
component if how == true remove it if false.
|
PackAs |
setAnchorNorthEast(boolean how)
Add anchor=NORTHEAST to the constraints for the current
component if how == true remove it if false.
|
PackAs |
setAnchorNorthWest(boolean how)
Add anchor=NORTHWEST to the constraints for the current
component if how == true remove it if false.
|
PackAs |
setAnchorSouth(boolean how)
Add anchor=SOUTH to the constraints for the current
component if how == true remove it if false.
|
PackAs |
setAnchorSouthEast(boolean how)
Add anchor=SOUTHEAST to the constraints for the current
component if how == true remove it if false.
|
PackAs |
setAnchorSouthWest(boolean how)
Add anchor=SOUTHWEST to the constraints for the current
component if how == true remove it if false.
|
PackAs |
setAnchorWest(boolean how)
Add anchor=WEST to the constraints for the current
component if how == true remove it if false.
|
PackAs |
setContainer(java.awt.Container cont)
Set the designated container for objects packed by this instance.
|
PackAs |
setFillBoth(boolean how)
Add fill=BOTH, weightx=1, weighty=1 to the constraints for the current
component if how == true, fill=0, weightx=0, weighty=0 if it is false.
|
PackAs |
setFillX(boolean how)
Add fill=HORIZONTAL, weightx=1 to the constraints for the current
component if how == true.
|
PackAs |
setFillY(boolean how)
Add fill=VERITCAL to the constraints for the current
component if how == true 1 it if false.
|
PackAs |
setInsetBottom(int val)
sets bottom Insets on the constraints for the current
component to the value specified.
|
PackAs |
setInsetLeft(int val)
sets left Insets on the constraints for the current
component to the value specified.
|
PackAs |
setInsetRight(int val)
sets right Insets on the constraints for the current
component to the value specified.
|
PackAs |
setInsetTop(int val)
sets top Insets on the constraints for the current
component to the value specified.
|
PackAs |
setRemainX(boolean how)
Add gridWidth=REMAINDER to the constraints for the current
component if how == true 1 it if false.
|
PackAs |
setRemainY(boolean how)
Add gridWidth=REMAINDER to the constraints for the current
component if how == true 1 it if false.
|
PackAs |
setXLeftRelative(boolean how)
Add gridx=RELATIVE to the constraints for the current
component if how == true 0 it if false.
|
PackAs |
setXRightRelative(boolean how)
Add gridWidth=RELATIVE to the constraints for the current
component if how == true 1 it if false.
|
PackAs |
setYBottomRelative(boolean how)
Add gridWidth=RELATIVE to the constraints for the current
component if how == true 1 it if false.
|
PackAs |
setYTopRelative(boolean how)
Add gridy=RELATIVE to the constraints for the current
component if how == true 0 it if false.
|
PackAs |
south()
Add anchor=SOUTH to the constraints for the current
component.
|
PackAs |
southeast()
Add anchor=SOUTHEAST to the constraints for the current
component.
|
PackAs |
southwest()
Add anchor=SOUTHWEST to the constraints for the current
component.
|
PackAs |
top()
Add gridy=RELATIVE to the constraints for the current
component.
|
PackAs |
weightx(double wt)
Add weightx=wt to the constraints for the current
component.
|
PackAs |
weighty(double wt)
Add weighty=wt to the constraints for the current
component.
|
PackAs |
west()
Add anchor=WEST to the constraints for the current
component.
|
addLayoutComponent, addLayoutComponent, adjustForGravity, AdjustForGravity, arrangeGrid, ArrangeGrid, getConstraints, getLayoutAlignmentX, getLayoutAlignmentY, getLayoutDimensions, getLayoutInfo, GetLayoutInfo, getLayoutOrigin, getLayoutWeights, getMinSize, GetMinSize, invalidateLayout, layoutContainer, location, lookupConstraints, maximumLayoutSize, minimumLayoutSize, preferredLayoutSize, removeLayoutComponent, setConstraints, toStringprotected java.awt.GridBagConstraints gc
protected java.awt.Component comp
protected java.awt.Container container
public Packer()
public Packer(java.awt.Container cont)
public java.lang.Object clone()
throws java.lang.CloneNotSupportedException
clone in class java.lang.Objectjava.lang.CloneNotSupportedException - if strange clone errors occurpublic PackAs setContainer(java.awt.Container cont) throws java.lang.IllegalAccessException
cont - the Container to use to add the components to when
.pack() or .add() is invoked.java.lang.IllegalAccessException - if container already setpublic java.awt.Container getContainer()
public PackAs into(java.awt.Container cont) throws java.lang.IllegalAccessException
public PackAs pack(java.awt.Component cp)
public PackAs add(java.awt.Component cp)
public PackAs setAnchorNorth(boolean how)
public boolean getAnchorNorth()
public PackAs north()
public PackAs setAnchorSouth(boolean how)
public boolean getAnchorSouth()
public PackAs south()
public PackAs setAnchorEast(boolean how)
public boolean getAnchorEast()
public PackAs east()
public PackAs setAnchorWest(boolean how)
public boolean getAnchorWest()
public PackAs west()
public PackAs setAnchorNorthWest(boolean how)
public boolean getAnchorNorthWest()
public PackAs northwest()
public PackAs setAnchorSouthWest(boolean how)
public boolean getAnchorSouthWest()
public PackAs southwest()
public PackAs setAnchorNorthEast(boolean how)
public boolean getAnchorNorthEast()
public PackAs northeast()
public PackAs setAnchorSouthEast(boolean how)
public boolean getAnchorSouthEast()
public PackAs southeast()
public PackAs setXLeftRelative(boolean how)
public boolean getXLeftRelative()
public PackAs left()
public PackAs setYTopRelative(boolean how)
public boolean getYTopRelative()
public PackAs top()
public PackAs setXRightRelative(boolean how)
public boolean getXRightRelative()
public PackAs right()
public PackAs setYBottomRelative(boolean how)
public boolean getYBottomRelative()
public PackAs bottom()
public PackAs gridx(int tot)
public int getGridX()
public PackAs gridy(int tot)
public int getGridY()
public PackAs gridw(int tot)
public int getGridW()
public PackAs gridh(int tot)
public int getGridH()
public PackAs padx(int cnt)
public int getPadX()
public PackAs pady(int cnt)
public int getPadY()
public PackAs setFillX(boolean how)
public boolean getFillX()
public PackAs fillx()
public PackAs setFillY(boolean how)
public boolean getFillY()
public PackAs filly()
public PackAs setFillBoth(boolean how)
public boolean getFillBoth()
public PackAs fillboth()
public PackAs inset(java.awt.Insets insets)
public PackAs setInsetTop(int val)
public int getInsetTop()
public int getInsetBottom()
public int getInsetLeft()
public int getInsetRight()
public PackAs setInsetBottom(int val)
public PackAs setInsetLeft(int val)
public PackAs setInsetRight(int val)
public PackAs inset(int top, int left, int bottom, int right)
public PackAs weightx(double wt)
public double getWeightX()
public double getWeightY()
public PackAs weighty(double wt)
public PackAs setRemainX(boolean how)
public boolean getRemainX()
public PackAs remainx()
public PackAs setRemainY(boolean how)
public boolean getRemainY()