|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectinfo.clearthought.layout.TableLayout
TableLayout is a layout manager that arranges components in rows and columns like a spreadsheet. TableLayout allows each row or column to be a different size. A row or column can be given an absolute size in pixels, a percentage of the available space, or it can grow and shrink to fill the remaining space after other rows and columns have been resized.
Using spreadsheet terminology, a cell is the intersection of a row and column. Cells have finite, non-negative sizes measured in pixels. The dimensions of a cell depend solely upon the dimensions of its row and column.
A component occupies a rectangular group of one or more cells. The component can be aligned in four ways within that cell.
A component can be stretched horizontally to fit the cell set (full justification), or it can be placed in the center of the cell. The component could also be left justified or right justified. Similarly, the component can be full, center, top, or bottom justified along the
public static void main (String args[])
{
// Create a frame
Frame frame = new Frame("Example of TableLayout");
frame.setBounds (100, 100, 300, 300);
// Create a TableLayout for the frame
double border = 10;
double size[][] =
{{border, 0.10, 20, TableLayout.FILL, 20, 0.20, border}, // Columns
{border, 0.20, 20, TableLayout.FILL, 20, 0.20, border}}; // Rows
frame.setLayout (new TableLayout(size));
// Create some buttons
String label[] = {"Top", "Bottom", "Left", "Right", "Center", "Overlap"};
Button button[] = new Button[label.length];
for (int i = 0; i < label.length; i++)
button[i] = new Button(label[i]);
// Add buttons
frame.add (button[0], "1, 1, 5, 1"); // Top
frame.add (button[1], "1, 5, 5, 5"); // Bottom
frame.add (button[2], "1, 3 "); // Left
frame.add (button[3], "5, 3 "); // Right
frame.add (button[4], "3, 3, c, c"); // Center
frame.add (button[5], "3, 3, 3, 5"); // Overlap
// Allow user to close the window to terminate the program
frame.addWindowListener
(new WindowListener()
{
public void windowClosing (WindowEvent e)
{
System.exit (0);
}
public void windowOpened (WindowEvent e) {}
public void windowClosed (WindowEvent e) {}
public void windowIconified (WindowEvent e) {}
public void windowDeiconified (WindowEvent e) {}
public void windowActivated (WindowEvent e) {}
public void windowDeactivated (WindowEvent e) {}
}
);
// Show frame
frame.show();
}
| Nested Class Summary | |
static class |
TableLayout.Entry
|
| Field Summary | |
protected static int |
C
Indicates a column |
protected static boolean |
checkForComponentOrientationSupport
Used to minimize reflection calls |
protected int[][] |
crOffset
Offsets of crs in pixels. |
protected int[][] |
crSize
Sizes of crs in pixels |
protected double[][] |
crSpec
Sizes of crs expressed in absolute and relative terms |
protected static double[][] |
defaultSize
Default row/column size |
protected boolean |
dirty
Indicates whether or not the size of the cells are known for the last known size of the container. |
protected int |
hGap
Horizontal gap between columns |
protected LinkedList |
list
List of components and their sizes |
protected static Method |
methodGetComponentOrientation
Method used to get component orientation while preserving compatability with earlier versions of java.awt.Container. |
protected int |
oldHeight
Previous known height of the container |
protected int |
oldWidth
Previous known width of the container |
protected static int |
R
Indicates a row |
protected int |
vGap
Vertical gap between rows |
| Fields inherited from interface info.clearthought.layout.TableLayoutConstants |
BOTTOM, CENTER, FILL, FULL, LEADING, LEFT, MINIMUM, PREFERRED, RIGHT, TOP, TRAILING |
| Constructor Summary | |
TableLayout()
Constructs an instance of TableLayout. |
|
TableLayout(double[][] size)
Constructs an instance of TableLayout. |
|
TableLayout(double[] col,
double[] row)
Constructs an instance of TableLayout. |
|
| Method Summary | |
void |
addLayoutComponent(Component component,
Object constraint)
Adds the specified component with the specified name to the layout. |
void |
addLayoutComponent(String name,
Component component)
Adds the specified component with the specified name to the layout. |
protected int |
assignAbsoluteSize(int z,
int availableSize)
Assigns absolute sizes. |
protected void |
assignFillSize(int z,
int availableSize)
Assigns FILL sizes. |
protected int |
assignPrefMinSize(int z,
int availableSize,
double typeOfSize)
Assigned widths to preferred and minimum size columns and rows. |
protected int |
assignRelativeSize(int z,
int availableSize)
Assigns relative sizes. |
protected Dimension |
calculateLayoutSize(Container container,
double typeOfSize)
Calculates the preferred or minimum size for the methods preferredLayoutSize and minimumLayoutSize. |
protected int |
calculateLayoutSize(Container container,
int z,
double typeOfSize,
TableLayout.Entry[] entryList,
Dimension[] prefMinSize)
Calculates the preferred or minimum size for the method calculateLayoutSize(Container container, double typeOfSize). |
protected void |
calculateOffset(int z,
Insets inset)
Calculates the offset of each cr. |
protected void |
calculateSize(Container container)
Calculates the sizes of the rows and columns based on the absolute and relative sizes specified in crSpec[R] and crSpec[C]
and the size of the container. |
protected int[] |
calculateSizeAndOffset(TableLayout.Entry entry,
int preferredSize,
boolean isColumn)
Calculates the vertical/horizontal offset and size of a component. |
void |
deleteColumn(int i)
Deletes a column in this layout. |
protected void |
deleteCr(int z,
int i)
Deletes a cr for the methods deleteRow or deleteColumn. |
void |
deleteRow(int i)
Deletes a row in this layout. |
double[] |
getColumn()
Gets the sizes of columns in this layout. |
double |
getColumn(int i)
Gets the width of a single column in this layout. |
protected ComponentOrientation |
getComponentOrientation(Container container)
Gets the container's component orientation. |
TableLayoutConstraints |
getConstraints(Component component)
Gets the constraints of a given component. |
int |
getHGap()
Gets the horizontal gap between colunns. |
List |
getInvalidEntry()
Determines whether or not there are any components with invalid constraints. |
float |
getLayoutAlignmentX(Container parent)
Returns the alignment along the x axis. |
float |
getLayoutAlignmentY(Container parent)
Returns the alignment along the y axis. |
int |
getNumColumn()
Gets the number of columns in this layout. |
int |
getNumRow()
Gets the number of rows in this layout. |
List |
getOverlappingEntry()
Gets a list of overlapping components and their constraints. |
double[] |
getRow()
Gets the height of a single row in this layout. |
double |
getRow(int i)
Gets the sizes of a row in this layout. |
int |
getVGap()
Gets the vertical gap between rows. |
protected void |
init(double[] col,
double[] row)
Initializes the TableLayout for all constructors. |
void |
insertColumn(int i,
double size)
Inserts a column in this layout. |
void |
insertCr(int z,
int i,
double size)
Inserts a cr for the methods insertRow or insertColumn. |
void |
insertRow(int i,
double size)
Inserts a row in this layout. |
void |
invalidateLayout(Container target)
Invalidates the layout, indicating that if the layout manager has cached information it should be discarded. |
void |
layoutContainer(Container container)
To lay out the specified container using this layout. |
Dimension |
maximumLayoutSize(Container target)
Returns the maximum dimensions for this layout given the components in the specified target container. |
Dimension |
minimumLayoutSize(Container container)
Determines the minimum size of the container argument using this layout. |
Dimension |
preferredLayoutSize(Container container)
Determines the preferred size of the container argument using this layout. |
void |
removeLayoutComponent(Component component)
Removes the specified component from the layout. |
void |
setColumn(double[] column)
Adjusts the number and sizes of rows in this layout. |
void |
setColumn(int i,
double size)
Adjusts the width of a single column in this layout. |
void |
setConstraints(Component component,
TableLayoutConstraints constraint)
Sets the constraints of a given component. |
protected void |
setCr(int z,
double[] size)
Sets the sizes of rows or columns for the methods setRow or setColumn. |
protected void |
setCr(int z,
int i,
double size)
Sets the sizes of rows or columns for the methods setRow or setColumn. |
void |
setHGap(int hGap)
Sets the horizontal gap between colunns. |
void |
setRow(double[] row)
Adjusts the number and sizes of rows in this layout. |
void |
setRow(int i,
double size)
Adjusts the height of a single row in this layout. |
void |
setVGap(int vGap)
Sets the vertical gap between rows. |
String |
toString()
Converts this TableLayout to a string. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
protected static final double[][] defaultSize
protected static final int C
protected static final int R
protected static boolean checkForComponentOrientationSupport
protected static Method methodGetComponentOrientation
protected double[][] crSpec
protected int[][] crSize
protected int[][] crOffset
protected LinkedList list
protected boolean dirty
protected int oldWidth
protected int oldHeight
protected int hGap
protected int vGap
| Constructor Detail |
public TableLayout()
public TableLayout(double[][] size)
size - widths of columns and heights of rows in the format,
{{col0, col1, col2, ..., colN}, {row0, row1, row2, ..., rowM}}
If this parameter is invalid, the TableLayout will have
exactly one row and one column.
public TableLayout(double[] col,
double[] row)
col - widths of columns in the format, {{col0, col1, col2, ..., colN}row - heights of rows in the format, {{row0, row1, row2, ..., rowN}| Method Detail |
protected void init(double[] col,
double[] row)
col - widths of columns in the format, {{col0, col1, col2, ..., colN}row - heights of rows in the format, {{row0, row1, row2, ..., rowN}public TableLayoutConstraints getConstraints(Component component)
component - desired component
public void setConstraints(Component component,
TableLayoutConstraints constraint)
component - desired component. This parameter cannot be null.constraint - new set of constraints. This parameter cannot be null.
public void setColumn(double[] column)
layout.layoutContainer(container);
container.repaint();
or
window.pack()
If this is not done, the changes in the layout will not be seen until the
container is resized.
column - widths of each of the columnsgetColumn()public void setRow(double[] row)
layout.layoutContainer(container);
container.repaint();
or
window.pack()
If this is not done, the changes in the layout will not be seen until the
container is resized.
row - heights of each of the rows. This parameter cannot be null.getRow()
protected void setCr(int z,
double[] size)
z - indicates row or columnsize - new cr size
public void setColumn(int i,
double size)
layout.layoutContainer(container);
container.repaint();
or
window.pack()
If this is not done, the changes in the layout will not be seen until the
container is resized.
i - zero-based index of column to set. If this parameter is not
valid, an ArrayOutOfBoundsException will be thrown.size - width of the column. This parameter cannot be null.getColumn()
public void setRow(int i,
double size)
layout.layoutContainer(container);
container.repaint();
or
window.pack()
If this is not done, the changes in the layout will not be seen until the
container is resized.
i - zero-based index of row to set. If this parameter is not
valid, an ArrayOutOfBoundsException will be thrown.size - height of the row. This parameter cannot be null.getRow()
protected void setCr(int z,
int i,
double size)
z - indicates row or columni - indicates which cr to resizesize - new cr sizepublic double[] getColumn()
setColumn(double[])public double[] getRow()
setRow(double[])public double getColumn(int i)
i - zero-based index of row to get. If this parameter is not valid,
an ArrayOutOfBoundsException will be thrown.
setRow(double[])public double getRow(int i)
i - zero-based index of row to get. If this parameter is not valid,
an ArrayOutOfBoundsException will be thrown.
setRow(double[])public int getNumColumn()
public int getNumRow()
public int getHGap()
public int getVGap()
public void setHGap(int hGap)
hGap - the horizontal gap in pixelspublic void setVGap(int vGap)
vGap - the horizontal gap in pixels
public void insertColumn(int i,
double size)
setColumn.
i - zero-based index at which to insert the columnsize - size of the column to be insertedsetColumn(double[]),
deleteColumn(int)
public void insertRow(int i,
double size)
setRow.
i - zero-based index at which to insert the rowsize - size of the row to be insertedsetRow(double[]),
deleteRow(int)
public void insertCr(int z,
int i,
double size)
z - indicates row or columni - zero-based index at which to insert the crsize - size of cr being insertedpublic void deleteColumn(int i)
setColumn.
i - zero-based index of column to deletesetColumn(double[]),
deleteColumn(int)public void deleteRow(int i)
setRow. There must be at least two rows in order
to delete a row.
i - zero-based index of row to deletesetRow(double[]),
deleteRow(int)
protected void deleteCr(int z,
int i)
z - indicates row or columni - zero-based index of cr to deletepublic String toString()
public List getInvalidEntry()
getOverlappingEntry()public List getOverlappingEntry()
getInvalidEntry()protected void calculateSize(Container container)
crSpec[R] and crSpec[C]
and the size of the container. The result is stored in crSize[R]
and crSize[C].
container - container using this TableLayout
protected int assignAbsoluteSize(int z,
int availableSize)
z - indicates row or columnavailableSize - amount of space available in the container
protected int assignRelativeSize(int z,
int availableSize)
z - indicates row or columnavailableSize - amount of space available in the container
protected void assignFillSize(int z,
int availableSize)
z - indicates row or columnavailableSize - amount of space available in the container
protected void calculateOffset(int z,
Insets inset)
z - indicates row or column
protected int assignPrefMinSize(int z,
int availableSize,
double typeOfSize)
z - indicates row or columnavailableSize - amount of space available in the containertypeOfSize - indicates preferred or minimum
public void layoutContainer(Container container)
User code should not have to call this method directly.
layoutContainer in interface LayoutManagercontainer - container being served by this layout managerprotected ComponentOrientation getComponentOrientation(Container container)
container - Container whose orientation is being queried
protected int[] calculateSizeAndOffset(TableLayout.Entry entry,
int preferredSize,
boolean isColumn)
entry - entry containing component and contraintspreferredSize - previously calculated preferred width/height of
componentisColumn - if true, this method is being called to calculate
the offset/size of a column. if false,... of a row.
public Dimension preferredLayoutSize(Container container)
preferredLayoutSize in interface LayoutManagercontainer - container being served by this layout manager
public Dimension minimumLayoutSize(Container container)
minimumLayoutSize in interface LayoutManagercontainer - container being served by this layout manager
protected Dimension calculateLayoutSize(Container container,
double typeOfSize)
container - container whose size is being calculatedtypeOfSize - indicates preferred or minimum
protected int calculateLayoutSize(Container container,
int z,
double typeOfSize,
TableLayout.Entry[] entryList,
Dimension[] prefMinSize)
container - container whose size is being calculatedtypeOfSize - indicates preferred or minimumentryList - list of Entry objectsprefMinSize - list of preferred or minimum sizes
public void addLayoutComponent(String name,
Component component)
addLayoutComponent in interface LayoutManagername - indicates entry's position and anchorcomponent - component to add
public void addLayoutComponent(Component component,
Object constraint)
addLayoutComponent in interface LayoutManager2component - component to addconstraint - indicates entry's position and alignmentpublic void removeLayoutComponent(Component component)
removeLayoutComponent in interface LayoutManagercomponent - component being removedpublic Dimension maximumLayoutSize(Container target)
maximumLayoutSize in interface LayoutManager2target - the component which needs to be laid out
public float getLayoutAlignmentX(Container parent)
getLayoutAlignmentX in interface LayoutManager2public float getLayoutAlignmentY(Container parent)
getLayoutAlignmentY in interface LayoutManager2public void invalidateLayout(Container target)
invalidateLayout in interface LayoutManager2
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||