|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.gargoylesoftware.base.gui.TableLayout
The TableLayout lays out items based on a table of rows and columns.
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(TraceChannel)
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)
Field Summary |
Fields inherited from interface javax.swing.SwingConstants |
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST |
Constructor Summary | |
TableLayout()
Create a new TableLayout. |
Method Summary | |
void |
addLayoutComponent(Component comp,
Object constraints)
Add the specified component to the layout with the specified constraints. |
void |
addLayoutComponent(String name,
Component comp)
Add the specified component to the layout with the specified constraints. |
protected void |
assertNotNull(String fieldName,
Object fieldValue)
Verify that the specified value is not null. |
void |
drawOutlines(Graphics graphics)
A debugging method that draws lines on the parent component to show where the table cell boundaries are. |
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. |
TraceChannel |
getTraceChannel()
Return the trace channel. |
int |
getVerticalAlignment()
Return the vertical alignment. |
void |
invalidateLayout(Container target)
Invalidate the layout and throw away and temporary calculations. |
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. |
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 |
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. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public TableLayout()
Method Detail |
public void setVerticalAlignment(int alignment)
alignment
- The new vertical alignment.public void setHorizontalAlignment(int alignment)
alignment
- The new horizontal alignment.public void setMinimumRowHeight(int index, int size)
index
- The row that we are setting the height for.size
- The new minimum height.public void setMinimumColumnWidth(int index, int size)
index
- The column that we are setting the width for.size
- The new width.public void setRowExpandable(int index, boolean isExpandable)
index
- The row index.isExpandable
- true if the row is to be expandable.public void setColumnExpandable(int index, boolean isExpandable)
index
- The column index.isExpandable
- true if the column is to be expandable.public void setTraceChannel(TraceChannel channel)
channel
- The new trace channel.public void setIgnoreInvisibleComponents(boolean ignore)
ignore
- True if we should ignore them.public float getLayoutAlignmentX(Container target)
getLayoutAlignmentX
in interface LayoutManager2
target
- The container that this layout is managing.
public float getLayoutAlignmentY(Container target)
getLayoutAlignmentY
in interface LayoutManager2
target
- The container that this layout is managing.
public int getVerticalAlignment()
setVerticalAlignment(int)
public int getHorizontalAlignment()
public boolean isRowExpandable(int index)
index
- The row index
public boolean isColumnExpandable(int index)
index
- The column.
public TraceChannel getTraceChannel()
public boolean getIgnoreInvisibleComponents()
public void addLayoutComponent(String name, Component comp) throws UnsupportedOperationException
addLayoutComponent
in interface LayoutManager
name
- The constraints string.comp
- the component that is being
added.
UnsupportedOperationException
- If called.public void addLayoutComponent(Component comp, Object constraints)
addLayoutComponent
in interface LayoutManager2
comp
- The component that is being added.constraints
- The constraints object.TableLayoutConstraints.makeConstraints(String)
public void removeLayoutComponent(Component comp)
removeLayoutComponent
in interface LayoutManager
comp
- The component to remove.public Dimension minimumLayoutSize(Container parent)
minimumLayoutSize
in interface LayoutManager
parent
- The container that this layout is managing.
public Dimension preferredLayoutSize(Container parent)
preferredLayoutSize
in interface LayoutManager
parent
- The container that this layout is managing.
public void layoutContainer(Container parent)
layoutContainer
in interface LayoutManager
parent
- The container that this layout is managing.public Dimension maximumLayoutSize(Container target)
maximumLayoutSize
in interface LayoutManager2
target
- The container that this layout is managing.
public void invalidateLayout(Container target)
invalidateLayout
in interface LayoutManager2
target
- The container that this layout is managing.public void drawOutlines(Graphics graphics)
graphics
- The graphics object.TableLayoutDebuggingPanel
protected final void assertNotNull(String fieldName, Object fieldValue) throws DetailedNullPointerException
fieldName
- The name of the field to checkfieldValue
- The value of the field to check
DetailedNullPointerException
- If fieldValue is null
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |