|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object acm.gui.TableLayout
public class TableLayout
This class implements a new LayoutManager
that arranges
components into a two-dimensional grid. The capabilities are analogous
to those provide by the GridBagLayout
class, although
TableLayout
is considerably easier to use.
The constructor for the TableLayout
class takes the number
of rows and columns. Thus, the constructor call
new TableLayout(3, 5)
creates a new TableLayout
manager with three rows in the
vertical dimension and five columns across the page. Components are added
to the grid starting at the upper left, filling each horizontal row and
then moving on to the next row down after the current one is filled.
The TableLayout
manager also supports more fine-grained
control over the formatting of tables by allowing you to specify
constraints in the following form:
constraint
=
value
For example, if you want to specify that a component occupies two columns in the grid, you would use the constraint
"gridwidth=2"
Strings used as constraint objects can set several constraints at once by including multiple constraint/value pairs separated by spaces.
The TableLayout
class accepts all constraints supported
by GridBagLayout
. The most common constraints are shown
in the following table:
| ||||
| ||||
| ||||
| ||||
|
Field Summary | |
---|---|
static int |
BOTH
Resize component in both directions |
static int |
BOTTOM
Align table vertically at the bottom of its container |
static int |
CENTER
Center table in the container |
static int |
FILL
Expand table to fill its container |
static int |
HORIZONTAL
Resize component in horizontal direction only |
static int |
LEFT
Align table horizontally at the left of its container |
static int |
NONE
Do not resize component |
static int |
RIGHT
Align table horizontally at the right of its container |
static int |
TOP
Align table vertically at the top of its container |
static int |
VERTICAL
Resize component in vertical direction only |
Constructor Summary | |
---|---|
TableLayout()
Creates a new TableLayout object with no limits
on the number of rows and columns. |
|
TableLayout(int rows,
int columns)
Creates a new TableLayout object with the specified
number of rows and columns. |
|
TableLayout(int rows,
int columns,
int hgap,
int vgap)
Creates a new TableLayout object with the specified
row count, column count, alignment, horizontal gap, and vertical gap. |
Method Summary | |
---|---|
void |
addLayoutComponent(Component comp,
Object constraints)
Adds a component to the layout. |
void |
addLayoutComponent(String constraints,
Component comp)
Adds a component to the layout. |
int |
getColumnCount()
Returns the number of columns in the table. |
TableConstraints |
getConstraints(Component comp)
Returns a copy of the constraints requested for the specified component. |
int |
getDefaultFill()
Returns the default fill parameter for components in the table. |
int |
getHgap()
Returns the horizontal gap between components. |
int |
getHorizontalAlignment()
Returns the horizontal alignment for the table. |
float |
getLayoutAlignmentX(Container target)
Returns the alignment along the x-axis as described in the LayoutManager2 interface. |
float |
getLayoutAlignmentY(Container target)
Returns the alignment along the y-axis as described in the LayoutManager2 interface. |
int |
getRowCount()
Returns the number of rows in the table. |
int |
getVerticalAlignment()
Returns the vertical alignment for the table. |
int |
getVgap()
Returns the vertical gap between components. |
void |
invalidateLayout(Container target)
Indicates that the layout is no longer valid. |
boolean |
isStrictGridBagModel()
Returns true if this layout manager is treating multirow
cells exactly as GridBagLayout does. |
void |
layoutContainer(Container target)
Lays out the components in the target container. |
protected GridBagConstraints |
lookupConstraints(Component comp)
Returns the constraints object for the specified component. |
protected TableConstraints |
lookupConstraints(Component comp,
Container target)
Returns the TableConstraints object actually applied to the specified
component when it is laid out in the target container. |
Dimension |
maximumLayoutSize(Container target)
Calculates the maximum size for the FrameLayout component
when laid out in the target container. |
Dimension |
minimumLayoutSize(Container target)
Calculates the minimum size for the FrameLayout component
when laid out in the target container. |
Dimension |
preferredLayoutSize(Container target)
Calculates the preferred size for the FrameLayout component
when laid out in the target container. |
void |
removeLayoutComponent(Component comp)
Removes the specified component from the layout. |
void |
setColumnCount(int columns)
Resets the number of columns in the table. |
void |
setConstraints(Component comp,
GridBagConstraints constraints)
Sets the constraints for the component to a copy of the supplied constraints. |
void |
setConstraints(Component comp,
String constraints)
Sets the constraints for the component to the constraints specified by the string. |
void |
setDefaultFill(int fill)
Sets the default fill parameter for components in the table. |
void |
setHgap(int pixels)
Sets the horizontal gap between components. |
void |
setHorizontalAlignment(int align)
Sets the horizontal alignment for the table. |
void |
setRowCount(int rows)
Resets the number of rows in the table. |
void |
setStrictGridBagModel(boolean flag)
Sets a flag indicating whether the layout manager should match the model used in GridBagLayout even when that interpretation
seems wrong. |
void |
setVerticalAlignment(int align)
Sets the vertical alignment for the table. |
void |
setVgap(int pixels)
Sets the vertical gap between components. |
String |
toString()
Creates a printable representation of the layout. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final int BOTH
public static final int BOTTOM
public static final int CENTER
public static final int FILL
public static final int HORIZONTAL
public static final int LEFT
public static final int NONE
public static final int RIGHT
public static final int TOP
public static final int VERTICAL
Constructor Detail |
---|
public TableLayout()
TableLayout
object with no limits
on the number of rows and columns.
public TableLayout(int rows, int columns)
TableLayout
object with the specified
number of rows and columns.
rows
- The number of rows, or 0 for no limitcolumns
- The number of columns, or 0 for no limitpublic TableLayout(int rows, int columns, int hgap, int vgap)
TableLayout
object with the specified
row count, column count, alignment, horizontal gap, and vertical gap.
rows
- The number of rows, or 0 for no limitcolumns
- The number of columns, or 0 for no limithgap
- The horizontal gap between columnsvgap
- The vertical gap between rowsMethod Detail |
---|
public void addLayoutComponent(Component comp, Object constraints)
TableLayout
class overrides this method to allow for string constraints.
addLayoutComponent
in interface LayoutManager2
comp
- The component to be addedconstraints
- The constraint objectpublic void addLayoutComponent(String constraints, Component comp)
LayoutManager
.
addLayoutComponent
in interface LayoutManager
constraints
- The constraint stringcomp
- The component to be addedpublic int getColumnCount()
public TableConstraints getConstraints(Component comp)
TableConstraints
so that
clients can use this class in preference to GridBagConstraints
without needing a type cast.
comp
- The component whose constraints are requested
public int getDefaultFill()
public int getHgap()
public int getHorizontalAlignment()
public float getLayoutAlignmentX(Container target)
LayoutManager2
interface.
getLayoutAlignmentX
in interface LayoutManager2
target
- The container in which the layout is done
public float getLayoutAlignmentY(Container target)
LayoutManager2
interface.
getLayoutAlignmentY
in interface LayoutManager2
target
- The container in which the layout is done
public int getRowCount()
public int getVerticalAlignment()
public int getVgap()
public void invalidateLayout(Container target)
invalidateLayout
in interface LayoutManager2
target
- The container in which the layout is donepublic boolean isStrictGridBagModel()
true
if this layout manager is treating multirow
cells exactly as GridBagLayout
does.
true
if this manager is using the strict GridBagLayout
modelpublic void layoutContainer(Container target)
layoutContainer
in interface LayoutManager
target
- The container in which the layout is doneprotected GridBagConstraints lookupConstraints(Component comp)
comp
- The component to be constrained
protected TableConstraints lookupConstraints(Component comp, Container target)
TableConstraints
object actually applied to the specified
component when it is laid out in the target container. In the result of this method
the values of the gridx
, gridx
, gridwidth
,
and gridheight
fields are filled in according to the actual position
in the grid.
comp
- The component to be constrainedtarget
- The container in which the layout is done
public Dimension maximumLayoutSize(Container target)
FrameLayout
component
when laid out in the target
container.
maximumLayoutSize
in interface LayoutManager2
target
- The container in which the layout is done
public Dimension minimumLayoutSize(Container target)
FrameLayout
component
when laid out in the target
container.
minimumLayoutSize
in interface LayoutManager
target
- The container in which the layout is done
public Dimension preferredLayoutSize(Container target)
FrameLayout
component
when laid out in the target
container.
preferredLayoutSize
in interface LayoutManager
target
- The container in which the layout is done
public void removeLayoutComponent(Component comp)
removeLayoutComponent
in interface LayoutManager
comp
- The component to be removedpublic void setColumnCount(int columns)
columns
- The new number of columnspublic void setConstraints(Component comp, GridBagConstraints constraints)
comp
- The component to be constrainedconstraints
- The constraints object used to specify the layoutpublic void setConstraints(Component comp, String constraints)
comp
- The component to be constrainedconstraints
- A string specifying the constraintspublic void setDefaultFill(int fill)
NONE
, HORIZONTAL
, VERTICAL
, and
BOTH
.
fill
- The default fill parameter for components in the tablepublic void setHgap(int pixels)
pixels
- The gap between components in pixelspublic void setHorizontalAlignment(int align)
CENTER
, LEFT
, RIGHT
, and
FILL
.
align
- The horizontal alignment for the tablepublic void setRowCount(int rows)
rows
- The new number of rowspublic void setStrictGridBagModel(boolean flag)
GridBagLayout
even when that interpretation
seems wrong. The differences show up in the following areas:
GridBagLayout
uses
the minimum layout size of the component to determine the size of each
cell; TableLayout
uses the preferred size. In practice,
these two values are often the same, but it seems that the preferred
size makes considerably more sense in terms of how this layout is used.
GridBagLayout
, each new row begins after the last
multirow cell in that row, even if there is space to its left.
By default, TableLayout
uses the HTML model in which
the cells begin at the left margin unless that column is itself
already occupied.
flag
- true
to use a strict GridBagLayout
modelpublic void setVerticalAlignment(int align)
CENTER
, TOP
, BOTTOM
, and
FILL
.
align
- The vertical alignment for the tablepublic void setVgap(int pixels)
pixels
- The gap between components in pixelspublic String toString()
toString
in class Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |