Package com.bc.ceres.swing
Class TableLayout
- java.lang.Object
-
- com.bc.ceres.swing.TableLayout
-
- All Implemented Interfaces:
LayoutManager
,LayoutManager2
public class TableLayout extends Object implements LayoutManager2
A convenient layout manager that allows multiple components to be laid out in form of a table-like grid.It uses the same parameters as Swing's standard
GridBagLayout
manager, however clients don't have to deal withGridBagConstraints
. Instead, they can easily use the the various setters to adjust single parameters. Parameters can be specified for- the entire table:
setTable<Param>()
, - an entire row:
setRow<Param>()
, - an entire column:
setColumn<Param>()
, - each cell separately:
setCell<Param>()
.
fill
andanchor
parameter values.Any parameter settings may be removed from the layout by passing
null
as value.Components are added to their container using a
cell(row, col)
orcell(row, col, rowspan, colspan)
constraint, for example:panel.add(new JLabel("Iterations:"), TableLayout.cell(0, 3));
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
TableLayout.Anchor
This parameter is used when the component's display area is larger than the component's requested size.static class
TableLayout.Cell
static class
TableLayout.Fill
This parameter is used when the component is smaller than its display area.
-
Constructor Summary
Constructors Constructor Description TableLayout()
TableLayout(int columnCount)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addLayoutComponent(Component comp, Object constraints)
Adds the specified component to the layout, using the specified constraint object.void
addLayoutComponent(String name, Component comp)
Has no effect, since this layout manager does not use a per-component string.static TableLayout.Cell
cell()
static TableLayout.Cell
cell(int row, int col)
static TableLayout.Cell
cell(int row, int col, int rowspan, int colspan)
Component
createHorizontalSpacer()
Component
createVerticalSpacer()
int
getColumnCount()
float
getLayoutAlignmentX(Container target)
Returns the alignment along the x axis.float
getLayoutAlignmentY(Container target)
Returns the alignment along the y axis.void
invalidateLayout(Container target)
Invalidates the layout, indicating that if the layout manager has cached information it should be discarded.void
layoutContainer(Container parent)
Lays out the specified container.Dimension
maximumLayoutSize(Container parent)
Calculates the maximum size dimensions for the specified container, given the components it contains.Dimension
minimumLayoutSize(Container parent)
Calculates the minimum size dimensions for the specified container, given the components it contains.Dimension
preferredLayoutSize(Container parent)
Calculates the preferred size dimensions for the specified container, given the components it contains.void
removeLayoutComponent(Component comp)
Removes the specified component from the layout.void
setCellAnchor(int row, int col, TableLayout.Anchor anchor)
void
setCellColspan(int row, int col, Integer colspan)
void
setCellFill(int row, int col, TableLayout.Fill fill)
void
setCellPadding(int row, int col, Insets insets)
void
setCellRowspan(int row, int col, Integer rowspan)
void
setCellWeightX(int row, int col, Double weightx)
void
setCellWeightY(int row, int col, Double weighty)
void
setColumnAnchor(int col, TableLayout.Anchor anchor)
void
setColumnCount(int columnCount)
void
setColumnFill(int col, TableLayout.Fill fill)
void
setColumnPadding(int col, Insets insets)
void
setColumnWeightX(int col, Double weightx)
void
setColumnWeightY(int col, Double weighty)
void
setRowAnchor(int row, TableLayout.Anchor anchor)
void
setRowFill(int row, TableLayout.Fill fill)
void
setRowPadding(int row, Insets insets)
void
setRowWeightX(int row, Double weightx)
void
setRowWeightY(int row, Double weighty)
void
setTableAnchor(TableLayout.Anchor anchor)
void
setTableFill(TableLayout.Fill fill)
void
setTablePadding(int hpadding, int vpadding)
void
setTablePadding(Insets insets)
void
setTableWeightX(Double weightx)
void
setTableWeightY(Double weighty)
String
toString()
-
-
-
Method Detail
-
getColumnCount
public int getColumnCount()
-
setColumnCount
public void setColumnCount(int columnCount)
-
setCellColspan
public void setCellColspan(int row, int col, Integer colspan)
-
setCellRowspan
public void setCellRowspan(int row, int col, Integer rowspan)
-
setTablePadding
public void setTablePadding(int hpadding, int vpadding)
-
setTablePadding
public void setTablePadding(Insets insets)
-
setRowPadding
public void setRowPadding(int row, Insets insets)
-
setColumnPadding
public void setColumnPadding(int col, Insets insets)
-
setCellPadding
public void setCellPadding(int row, int col, Insets insets)
-
setTableWeightX
public void setTableWeightX(Double weightx)
-
setRowWeightX
public void setRowWeightX(int row, Double weightx)
-
setColumnWeightX
public void setColumnWeightX(int col, Double weightx)
-
setCellWeightX
public void setCellWeightX(int row, int col, Double weightx)
-
setTableWeightY
public void setTableWeightY(Double weighty)
-
setRowWeightY
public void setRowWeightY(int row, Double weighty)
-
setColumnWeightY
public void setColumnWeightY(int col, Double weighty)
-
setCellWeightY
public void setCellWeightY(int row, int col, Double weighty)
-
setTableFill
public void setTableFill(TableLayout.Fill fill)
-
setRowFill
public void setRowFill(int row, TableLayout.Fill fill)
-
setColumnFill
public void setColumnFill(int col, TableLayout.Fill fill)
-
setCellFill
public void setCellFill(int row, int col, TableLayout.Fill fill)
-
setTableAnchor
public void setTableAnchor(TableLayout.Anchor anchor)
-
setRowAnchor
public void setRowAnchor(int row, TableLayout.Anchor anchor)
-
setColumnAnchor
public void setColumnAnchor(int col, TableLayout.Anchor anchor)
-
setCellAnchor
public void setCellAnchor(int row, int col, TableLayout.Anchor anchor)
-
createHorizontalSpacer
public Component createHorizontalSpacer()
-
createVerticalSpacer
public Component createVerticalSpacer()
-
getLayoutAlignmentX
public float getLayoutAlignmentX(Container target)
Returns the alignment along the x axis. This specifies how the component would like to be aligned relative to other components. The value should be a number between 0 and 1 where 0 represents alignment along the origin, 1 is aligned the furthest away from the origin, 0.5 is centered, etc.- Specified by:
getLayoutAlignmentX
in interfaceLayoutManager2
-
getLayoutAlignmentY
public float getLayoutAlignmentY(Container target)
Returns the alignment along the y axis. This specifies how the component would like to be aligned relative to other components. The value should be a number between 0 and 1 where 0 represents alignment along the origin, 1 is aligned the furthest away from the origin, 0.5 is centered, etc.- Specified by:
getLayoutAlignmentY
in interfaceLayoutManager2
-
invalidateLayout
public void invalidateLayout(Container target)
Invalidates the layout, indicating that if the layout manager has cached information it should be discarded.- Specified by:
invalidateLayout
in interfaceLayoutManager2
-
addLayoutComponent
public void addLayoutComponent(Component comp, Object constraints)
Adds the specified component to the layout, using the specified constraint object.- Specified by:
addLayoutComponent
in interfaceLayoutManager2
- Parameters:
comp
- the component to be addedconstraints
- where/how the component is added to the layout.
-
addLayoutComponent
public void addLayoutComponent(String name, Component comp)
Has no effect, since this layout manager does not use a per-component string.- Specified by:
addLayoutComponent
in interfaceLayoutManager
-
removeLayoutComponent
public void removeLayoutComponent(Component comp)
Removes the specified component from the layout.- Specified by:
removeLayoutComponent
in interfaceLayoutManager
- Parameters:
comp
- the component to be removed
-
layoutContainer
public void layoutContainer(Container parent)
Lays out the specified container.- Specified by:
layoutContainer
in interfaceLayoutManager
- Parameters:
parent
- the container to be laid out
-
minimumLayoutSize
public Dimension minimumLayoutSize(Container parent)
Calculates the minimum size dimensions for the specified container, given the components it contains.- Specified by:
minimumLayoutSize
in interfaceLayoutManager
- Parameters:
parent
- the component to be laid out- See Also:
preferredLayoutSize(java.awt.Container)
-
preferredLayoutSize
public Dimension preferredLayoutSize(Container parent)
Calculates the preferred size dimensions for the specified container, given the components it contains.- Specified by:
preferredLayoutSize
in interfaceLayoutManager
- Parameters:
parent
- the container to be laid out- See Also:
minimumLayoutSize(java.awt.Container)
-
maximumLayoutSize
public Dimension maximumLayoutSize(Container parent)
Calculates the maximum size dimensions for the specified container, given the components it contains.- Specified by:
maximumLayoutSize
in interfaceLayoutManager2
- See Also:
Component.getMaximumSize()
,LayoutManager
-
cell
public static TableLayout.Cell cell()
-
cell
public static TableLayout.Cell cell(int row, int col)
-
cell
public static TableLayout.Cell cell(int row, int col, int rowspan, int colspan)
-
-