|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectgov.nasa.gsfc.drl.rtstps.library.layout.RowLayout
public final class RowLayout
This class is a layout manager. It forms rows of components. It appends components to rows, left-justifying them in each row.
RowLayout lays out a row similar to FlowLayout, except it does not wrap components to a new row. It sets components to their preferred widths. but if the container is not wide enough, it uses minimum widths instead.
When you give a component to RowLayout, you also assign it a row number and a weight, which is a floating point number between 0.0 and 1.0. The weight tells RowLayout how to distribute extra space in a row. If all components in a row have zero weight, then RowLayout left-justifies all of them, and it puts all extra space at the row's end. If one or more components has weight, then RowLayout assigns all extra space to those components by expanding their horizontal cell size. It gives a component a percentage of the extra space equal to the component's weight divided by the sum of all weights in that row. It ignores a component's maximum size. The horizontal layout of a row does not affect any other row.
You may add glue or horizontal glue to a row. (It ignores the vertical aspects of glue.) It treats glue as an invisible component with weight set to 1.0. It ignores any passed value for glue's weight and unconditionally uses 1.0 instead. (Set javax.swing.Box for glue components. You can also insert a blank panel with 1.0 weight.)
RowLayout sets the height of a row to the maximum preferred size of all components in a row. If the container is not tall enough, it uses minimum sizes instead. This means that all components in a row are expanded vertically to be the same size. RowLayout ignores a component's maximum size. You do not have to put components in every row.
You may assign weights to rows. The default row weight is 0.0. If all rows have zero weight, then RowLayout evenly distributes extra space to the vertical gaps and margins. If one or more rows have weight, then it gives those rows all extra space by expanding the vertical heights of weighted rows. It gives a row a percentage of the extra space equal to the row's weight divided by the sum of all row weights.
You may not add vertical glue to RowLayout. Instead, you should set a row's weight to a non-zero value (usually 1.0). You do not need to put components in that row or any row.
Pass a constraint object when you add a component to its container. The constraint class is RowLayout.Constraint { int row; float weight; } It has the convenience method void set(int row, float weight). RowLayout copies the Constraint object, so you only need to create one,
You may set hgap and vgap, which are the gaps between components. The default gap size is zero pixels. It does not apply to the border. You may set insets, which is the border.
RowLayout layout = new RowLayout(5); //five rows, no gaps JPanel jp = new JPanel(layout); RowLayout.Constraint lc = new RowLayout.Constraint(); layout.setRowWeight(0,1f); //vertical glue lc.set(1,1f); jp.add(comp1,lc); lc.set(1,1f); jp.add(Box.createGlue(),lc); lc.set(1,0f); jp.add(comp2,lc); lc.set(2,0f); jp.add(comp3,lc); lc.set(3,1f); jp.add(comp4,lc); layout.setRowWeight(4,1f); //vertical glue
Nested Class Summary | |
---|---|
static class |
RowLayout.Constraint
RowLayout's component constraint object. |
Field Summary | |
---|---|
private int |
_minLayoutWidth
|
private int |
_prefLayoutWidth
|
private boolean |
_valid
|
private WidthManager[] |
_xxxx
|
private HeightManager |
_yyyy
|
private static long |
serialVersionUID
|
Constructor Summary | |
---|---|
RowLayout(int rows)
Construct a RowLayout layout manager. |
|
RowLayout(int rows,
int hgap,
int vgap)
Construct a RowLayout layout manager. |
Method Summary | |
---|---|
void |
addLayoutComponent(java.awt.Component comp,
java.lang.Object constraint)
Add a component to the layout. |
void |
addLayoutComponent(java.lang.String name,
java.awt.Component comp)
Add a component to the layout. |
float |
getLayoutAlignmentX(java.awt.Container parent)
Get the horizontal alignment. |
float |
getLayoutAlignmentY(java.awt.Container parent)
Get the vertical alignment. |
void |
invalidateLayout(java.awt.Container parent)
Invalidate the layout. |
void |
layoutContainer(java.awt.Container parent)
Lay out the container's components. |
java.awt.Dimension |
maximumLayoutSize(java.awt.Container parent)
Get the container's maximum layout size. |
java.awt.Dimension |
minimumLayoutSize(java.awt.Container parent)
Get the container's minimum layout size. |
java.awt.Dimension |
preferredLayoutSize(java.awt.Container parent)
Get the container's preferred layout size. |
void |
removeLayoutComponent(java.awt.Component comp)
Remove a component from the layout. |
void |
setHgap(int gap)
Set the horizontal gap, which is the gap between columns. |
void |
setInsets(java.awt.Insets inset)
Set a border. |
void |
setRowWeight(float weight)
Set a row weight for all rows. |
void |
setRowWeight(int row,
float weight)
Set a row's weight. |
void |
setVgap(int gap)
Set the vertical gap, which is the gap between rows. |
private void |
validate()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private WidthManager[] _xxxx
private HeightManager _yyyy
private boolean _valid
private int _minLayoutWidth
private int _prefLayoutWidth
private static final long serialVersionUID
Constructor Detail |
---|
public RowLayout(int rows, int hgap, int vgap)
rows
- The number of rows must be greater than zero.hgap
- The horizontal gap between columns. Default is zero.vgap
- The vertical gap between rows. Default is zero.public RowLayout(int rows)
rows
- The number of rows must be greater than zero.Method Detail |
---|
public final void setHgap(int gap)
public final void setVgap(int gap)
public final void setInsets(java.awt.Insets inset)
public final void setRowWeight(float weight)
public final void setRowWeight(int row, float weight)
public final float getLayoutAlignmentX(java.awt.Container parent)
getLayoutAlignmentX
in interface java.awt.LayoutManager2
public final float getLayoutAlignmentY(java.awt.Container parent)
getLayoutAlignmentY
in interface java.awt.LayoutManager2
public final void invalidateLayout(java.awt.Container parent)
invalidateLayout
in interface java.awt.LayoutManager2
public void removeLayoutComponent(java.awt.Component comp)
removeLayoutComponent
in interface java.awt.LayoutManager
public void addLayoutComponent(java.lang.String name, java.awt.Component comp)
addLayoutComponent
in interface java.awt.LayoutManager
public void addLayoutComponent(java.awt.Component comp, java.lang.Object constraint)
addLayoutComponent
in interface java.awt.LayoutManager2
comp
- A componentconstraint
- This must be a RowLayout.Constraint object.private void validate()
public java.awt.Dimension minimumLayoutSize(java.awt.Container parent)
minimumLayoutSize
in interface java.awt.LayoutManager
public java.awt.Dimension preferredLayoutSize(java.awt.Container parent)
preferredLayoutSize
in interface java.awt.LayoutManager
public java.awt.Dimension maximumLayoutSize(java.awt.Container parent)
maximumLayoutSize
in interface java.awt.LayoutManager2
public void layoutContainer(java.awt.Container parent)
layoutContainer
in interface java.awt.LayoutManager
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |