com.gargoylesoftware.base.gui
public class TableLayout extends Object implements LayoutManager2, SwingConstants, Serializable
If you are doing simple layout, you can specify constraints as strings of the format "row,column". If you want the component to stretch over multiple rows/columns then you can specify the constraint as "row+rowspan,column+columnspan" as shown in the sample below.
final TableLayout layout = new TableLayout(); final JPanel panel = new JPanel(layout); panel.add( new JLabel("squirrel"), "1,1" ); panel.add( new JLabel("raccoon"), "1,2" ); panel.add( new JLabel("bluejay"), "2,1" ); panel.add( new JLabel("goldfish"), "2,2" ); panel.add( new JLabel("marshhawk"), "3,1+3" );If you want more flexibility over the layout then this, use a TableLayoutConstraints object instead of a string. Here is a more complicated sample that uses TableLayoutConstraints to customize the layout a bit more. Note the use of TableLayoutDebuggingPanel - this will draw lines on layout boundaries to help debug layout problems.
final TableLayout layout = new TableLayout(); final JPanel panel = new TableLayoutDebuggingPanel(layout); TableLayoutConstraints constraints; layout.setRowExpandable(1, true); constraints = new TableLayoutConstraints(1,1); constraints.setVerticalStretch(true); panel.add( new JButton("squirrel"), constraints ); constraints = new TableLayoutConstraints(1,2); constraints.setVerticalAlignment(TableLayout.TOP); panel.add( new JButton("raccoon"), constraints ); panel.add( new JButton("bluejay"), "2,1" ); panel.add( new JButton("goldfish"), "2,2" ); panel.add( new JButton("marshhawk"), "3,1+3" );Debugging tip: Most layout problems become obvious if you use a TableLayoutDebuggingPanel to see where the layout boundaries are. In those rare cases where this doesn't give you enough information, try calling setTraceChannel with a non-null TraceChannel such as Trace.out or Trace.err. This will dump quite a bit of diagnostic information.
layout.setTraceChannel(Trace.out)
Version: $Revision: 1.5 $
Nested Class Summary | |
---|---|
class | TableLayout.Entry
A convenience class to attach the constraints to a component. |
class | TableLayout.Header
A convenience class to hold information specific to a row or column. |
class | TableLayout.HeaderPermanentInfo
Contains the information that the user has specified for the specific
row or column. |
Field Summary | |
---|---|
Dimension | actualSize_ |
int | columnCount_ |
Set | columnHeaderPermanentInfos_ |
List | constraints_ |
int | horizontalAlignment_ |
boolean | ignoreInvisibleComponents_ |
Dimension | maximumSize_ |
Dimension | minimumSize_ |
Container | parent_ |
Dimension | preferredSize_ |
int | rowCount_ |
Set | rowHeaderPermanentInfos_ |
static long | serialVersionUID |
TableLayout.Header[] | tempColumnHeaders_ |
TableLayout.Header[] | tempRowHeaders_ |
boolean | tempSizesAreValid_ |
TraceChannel | traceChannel_ |
int | verticalAlignment_ |
Constructor Summary | |
---|---|
TableLayout()
Create a new TableLayout. |
Method Summary | |
---|---|
void | addLayoutComponent(String name, Component comp)
Add the specified component to the layout with the specified
constraints. |
void | addLayoutComponent(Component comp, Object constraints)
Add the specified component to the layout with the specified
constraints. |
void | adjustHeaderSizes(TableLayout.Header[] sizes)
Fix up all the headers such that minimum <= preferred <= maximum
|
void | adjustSizesForSpanning(int start, int span, TableLayout.Header[] sizes, int minSize, int preferredSize, int maxSize)
Adjust the various sizes to account for components than span multiple
columns/rows.
|
boolean | areAnyExpandable(Set permanentInfos)
Return true if any of the infos are expandable.
|
protected void | assertNotNull(String fieldName, Object fieldValue)
Verify that the specified value is not null. |
void | calculateActualSizes(Dimension parentSize)
Calculate the actual sizes to be used based on the actual dimension of
the parent container.
|
int | calculateActualSizes(TableLayout.Header[] sizes, int preferredLength, int clipLength)
Calculate the actual sizes for the specified row or column headers.
|
void | calculateMinMaxPreferredSizes()
Calculate the various sizes. |
void | calculatePositions(Container parent, Dimension parentSize)
Calculate all the positions of the various rows/columns
|
void | calculateRowAndColumnCount()
The list of constraints has been modified. |
void | calculateSizes()
Calculate all the various sizing information required for this layout.
|
void | drawOutlines(Graphics graphics)
A debugging method that draws lines on the parent component to show
where the table cell boundaries are. |
void | expandToFit(TableLayout.Header[] sizes, int clipLength)
Expand the specified sizes to fit within the specified clipLength.
|
Dimension | getComponentMaximumSize(Component component)
Return the minimum size of the specified component. |
Dimension | getComponentMinimumSize(Component component)
Return the minimum size of the specified component. |
Dimension | getComponentPreferredSize(Component component)
Return the minimum size of the specified component. |
TableLayoutConstraints | getConstraints(Component component)
Return the TableLayoutConstraints object that corresponds to the
specified component or null if this component could not be found.
|
TableLayout.Header[] | getExpandableHeaders(int first, int last, TableLayout.Header[] headers)
Return an array containing all the headers that are expandable.
|
int | getHorizontalAlignment()
Return the horizontal alignment.
|
boolean | getIgnoreInvisibleComponents()
Get whether or not we should ignore an components that are not visible.
|
float | getLayoutAlignmentX(Container target)
I don't really understand what this method is supposed to return so I
always return 0F. |
float | getLayoutAlignmentY(Container target)
I don't really understand what this method is supposed to return so I
always return 0F. |
int | getMinimumColumnWidth(int index)
Return the minimum column width. |
int | getMinimumRowHeight(int index)
Return the minimum row height. |
TableLayout.HeaderPermanentInfo | getPermanentInfo(Set infoList, int index, boolean createIfNeeded)
TODO: Provide comments
|
TraceChannel | getTraceChannel()
Return the trace channel.
|
int | getVerticalAlignment()
Return the vertical alignment.
|
void | initTempSizes()
Initialize the temporary arrays (tempRowHeaders_ and tempColumnHeaders_)
for use in a calculation. |
void | invalidateLayout(Container target)
Invalidate the layout and throw away and temporary calculations.
|
void | invalidateLayout()
Invalidate the layout. |
boolean | isColumnExpandable(int index)
Return true if this column can be expanded beyond its preferred size.
|
boolean | isRowExpandable(int index)
Return true if this row can be expanded beyond its preferred size. |
void | layoutContainer(Container parent)
Layout all the components in this container.
|
Dimension | maximumLayoutSize(Container target)
Return the maximum layout size.
|
Dimension | minimumLayoutSize(Container parent)
Get the minimum size of this layout.
|
void | positionComponent(TableLayout.Entry entry, int x, int y, int width, int height)
Position one component given the bounding coordinates
|
Dimension | preferredLayoutSize(Container parent)
Return the preferred layout size.
|
void | removeLayoutComponent(Component comp)
Remove the specified component from the layout.
|
void | setColumnExpandable(int index, boolean isExpandable)
Set whether this column can be expanded beyond its preferred size.
|
void | setHorizontalAlignment(int alignment)
Set the vertical alignment. |
void | setIgnoreInvisibleComponents(boolean ignore)
Set whether or not we should ignore an components that are not visible.
|
void | setMinimumColumnWidth(int index, int size)
Set the minimum column width for a specific column.
|
void | setMinimumRowHeight(int index, int size)
Set the minimum row height for a specific row.
|
void | setParent(Container newParent)
Set the parent container for this layout.
|
void | setRowExpandable(int index, boolean isExpandable)
Set whether this row can be expanded beyond its preferred size.
|
void | setTraceChannel(TraceChannel channel)
Set the trace channel used for printing diagnostic information. |
void | setVerticalAlignment(int alignment)
Set the vertical alignment. |
void | shrinkToFit(TableLayout.Header[] sizes, int clipLength)
Shrink the specified sizes to fit within the specified clipLength. |
static String | toString(Dimension dimension)
Convenience method to create a string from a Dimension object.
|
Parameters: name The constraints string. comp the component that is being added.
Throws: UnsupportedOperationException If called.
Parameters: comp The component that is being added. constraints The constraints object.
See Also: makeConstraints
Parameters: sizes Description of Parameter
Parameters: start The starting index of the component. span The number of columns/rows that the component spans. sizes The headers that we are adjusting. minSize The minimum size of the component. preferredSize The preferred size of the component. maxSize The maximum size of the component.
Parameters: permanentInfos The infos.
Returns: Description of the Returned Value
Parameters: fieldName The name of the field to check fieldValue The value of the field to check
Throws: DetailedNullPointerException If fieldValue is null
Parameters: parentSize Description of Parameter
Parameters: sizes Description of Parameter preferredLength Description of Parameter clipLength Description of Parameter
Returns: Description of the Returned Value
Parameters: parent Description of Parameter parentSize Description of Parameter
Parameters: graphics The graphics object.
See Also: TableLayoutDebuggingPanel
Parameters: sizes Description of Parameter clipLength Description of Parameter
Parameters: component The component that we will be querying
Returns: The size
Parameters: component The component that we will be querying
Returns: The size
Parameters: component The component that we will be querying
Returns: The size
Parameters: component Description of Parameter
Returns: The constraints value
Parameters: first Description of Parameter last Description of Parameter headers Description of Parameter
Returns: The expandableHeaders value
Returns: The horizontal alignment.
Returns: True if we should ignore them.
Parameters: target The container that this layout is managing.
Returns: Zero.
Parameters: target The container that this layout is managing.
Returns: Zero.
Parameters: index The column index.
Returns: The minimum column width for the specified column.
Parameters: index Description of Parameter
Returns: The minimumRowHeight value
Parameters: infoList Description of Parameter index Description of Parameter createIfNeeded Description of Parameter
Returns: The permanentInfo value
Returns: The trace channel or null if one wasn't set.
Returns: The vertical alignment.
See Also: TableLayout
Parameters: target The container that this layout is managing.
Parameters: index The column.
Returns: true if the column is expandable.
Parameters: index The row index
Returns: true if the specified row is expandable.
Parameters: parent The container that this layout is managing.
Parameters: target The container that this layout is managing.
Returns: The maximum layout size.
Parameters: parent The container that this layout is managing.
Returns: The minimum size required for this layout.
Parameters: entry Description of Parameter x Description of Parameter y Description of Parameter width Description of Parameter height Description of Parameter
Parameters: parent The container that this layout is managing.
Returns: The preferred layout size.
Parameters: comp The component to remove.
Parameters: index The column index. isExpandable true if the column is to be expandable.
Parameters: alignment The new horizontal alignment.
Parameters: ignore True if we should ignore them.
Parameters: index The column that we are setting the width for. size The new width.
Parameters: index The row that we are setting the height for. size The new minimum height.
Parameters: newParent The new parent value
Parameters: index The row index. isExpandable true if the row is to be expandable.
Parameters: channel The new trace channel.
Parameters: alignment The new vertical alignment.
Parameters: sizes Description of Parameter clipLength Description of Parameter
Parameters: dimension Description of Parameter
Returns: Description of the Returned Value