gov.nasa.gsfc.drl.rtstps.library.layout
Class RowLayout

java.lang.Object
  extended by gov.nasa.gsfc.drl.rtstps.library.layout.RowLayout
All Implemented Interfaces:
java.awt.LayoutManager, java.awt.LayoutManager2, java.io.Serializable

public final class RowLayout
extends java.lang.Object
implements java.awt.LayoutManager2, java.io.Serializable

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
 

See Also:
Serialized Form

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

_xxxx

private WidthManager[] _xxxx

_yyyy

private HeightManager _yyyy

_valid

private boolean _valid

_minLayoutWidth

private int _minLayoutWidth

_prefLayoutWidth

private int _prefLayoutWidth

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values
Constructor Detail

RowLayout

public RowLayout(int rows,
                 int hgap,
                 int vgap)
Construct a RowLayout layout manager.

Parameters:
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.

RowLayout

public RowLayout(int rows)
Construct a RowLayout layout manager.

Parameters:
rows - The number of rows must be greater than zero.
Method Detail

setHgap

public final void setHgap(int gap)
Set the horizontal gap, which is the gap between columns. The default is zero pixels. It does not apply to the outside border.


setVgap

public final void setVgap(int gap)
Set the vertical gap, which is the gap between rows. The default is zero pixels. It does not apply to the outside border.


setInsets

public final void setInsets(java.awt.Insets inset)
Set a border.


setRowWeight

public final void setRowWeight(float weight)
Set a row weight for all rows. The default weight of any row is 0.0f.


setRowWeight

public final void setRowWeight(int row,
                               float weight)
Set a row's weight. The default weight of any row is 0.0f.


getLayoutAlignmentX

public final float getLayoutAlignmentX(java.awt.Container parent)
Get the horizontal alignment. RowLayout does not use alignment.

Specified by:
getLayoutAlignmentX in interface java.awt.LayoutManager2

getLayoutAlignmentY

public final float getLayoutAlignmentY(java.awt.Container parent)
Get the vertical alignment. RowLayout does not use alignment.

Specified by:
getLayoutAlignmentY in interface java.awt.LayoutManager2

invalidateLayout

public final void invalidateLayout(java.awt.Container parent)
Invalidate the layout.

Specified by:
invalidateLayout in interface java.awt.LayoutManager2

removeLayoutComponent

public void removeLayoutComponent(java.awt.Component comp)
Remove a component from the layout.

Specified by:
removeLayoutComponent in interface java.awt.LayoutManager

addLayoutComponent

public void addLayoutComponent(java.lang.String name,
                               java.awt.Component comp)
Add a component to the layout. This is not a valid method for this layout manager.

Specified by:
addLayoutComponent in interface java.awt.LayoutManager

addLayoutComponent

public void addLayoutComponent(java.awt.Component comp,
                               java.lang.Object constraint)
Add a component to the layout.

Specified by:
addLayoutComponent in interface java.awt.LayoutManager2
Parameters:
comp - A component
constraint - This must be a RowLayout.Constraint object.

validate

private void validate()

minimumLayoutSize

public java.awt.Dimension minimumLayoutSize(java.awt.Container parent)
Get the container's minimum layout size.

Specified by:
minimumLayoutSize in interface java.awt.LayoutManager

preferredLayoutSize

public java.awt.Dimension preferredLayoutSize(java.awt.Container parent)
Get the container's preferred layout size.

Specified by:
preferredLayoutSize in interface java.awt.LayoutManager

maximumLayoutSize

public java.awt.Dimension maximumLayoutSize(java.awt.Container parent)
Get the container's maximum layout size.

Specified by:
maximumLayoutSize in interface java.awt.LayoutManager2

layoutContainer

public void layoutContainer(java.awt.Container parent)
Lay out the container's components.

Specified by:
layoutContainer in interface java.awt.LayoutManager