Overview | Package | Class | Tree | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.objexcel.gui
Class ArrayLayout

    java.lang.Object
      |
      +--com.objexcel.gui.ArrayLayout

public final class ArrayLayout
extends java.lang.Object

This class adapts the gridbaglayout to create a grid based layout. You pass in a 2-d array of components. The ArrayLayout will typically be used to create grids of label, field, label, field, etc. It does not do nestings so a group box of components would need to be added as a panel. With a combination of ArrayLayout, BorderLayout and Box Layout you should be able to accomplish pretty well any layout you can find. ArrayLayout creates rows with the height of the largest thing in them and ditto for columns.

    JComponent controls[] {
    {lText, lTextAndIcon} // this row will be as high as the taller of lText and lTextAndIcon
    };

    // this column will be as wide as the wider of lText and lTextAndIcon
    JComponent controls[] {
    {lText}
    ,{ lTextAndIcon}
    };

    If you want a component to spread over more than one column, list the
    component more than once in the array row.

    // this layout will put lLongLabel under both lShortLabel and tfLongTextField.
    // If it wasn't mentioned twice tfLongTextField would be to the right of the wider
    // of lShortLabel and lLongLabel
    JComponent controls[] {
    {lShortLabel, 	tfLongTextField}
    ,{ lLongLabel, 	lLongLabel}
    };

    You can also stagger components.  For example you may want to align the tops of a
    label and a list but you want the list to be taller than the label.

    // this example allows lLabel to be as high as its preferred size (not forcing it
    // to be as high as the list
    JComponent controls[] {
    {lLabel, 		listLongList}
    ,{null, 	listLongList}
    };

    The default sizing for all components is component's preferred size.  For lists and
    tables you should call their setPreferredSize method.  For textfields it is a good
    idea to use the constructor with a column size so all your texfields can have the same
    size independant of content size.

    The add method also allows you to specify an (optional) array of components so you can right
    align labels to their input components.

    The add method also allows you to specify an (optional) array of components that fill any
    leftover space.  This means these components will expand to take over extra space.

    example usage:
    JComponent controls[][] = {
    {lWorkGroupName, 		tfWorkGroupName, 		null, 	lServiceManagerName, 	tfServiceManagerName}
    ,{null, 			null, 			null, 	lAllocationCriteria,	tfAllocationCriteria}
    ,{null, 			null, 			null, 	lTotalFTE,			tfTotalFTE}
    ,{null, 			null, 			null, 	lDCUName,			tfDCUName}
    ,{lAvailableDCOs, 	lAvailableDCOs, 		null, 	lAssignedDCOs,		lAssignedDCOs}
    ,{tAvailableDCOs, 	tAvailableDCOs, 		null, 	tAssignedDCOs,		tAssignedDCOs}
    ,{tAvailableDCOs, 	tAvailableDCOs, 		btnLeft, 	tAssignedDCOs,		tAssignedDCOs}
    ,{tAvailableDCOs, 	tAvailableDCOs, 		btnRight, 	tAssignedDCOs,		tAssignedDCOs}
    ,{tAvailableDCOs, 	tAvailableDCOs, 		null, 	tAssignedDCOs,		tAssignedDCOs}
    };

    // ArrayLayout works on a preferred size for each component.
    // The preferred size for a table should be set manually (and the table wrapped in a scrollpane!)
    // if you're wrapping a scrollPane then tAvailableDCOs, tAssignedDCOs should be changed to the name of their scroller
    tAvailableDCOs.setPreferredSize(150,200);
    tAssignedDCOs.setPreferredSize(150,200);
    // make the labels right aligned by their text fields.
    JComponent rights = {lWorkGroupName, lServiceManagerName, lAllocationCriteria, lTotalFTE, lDCUName};
    // set these components to gobble up any extra space.
    JComponent fills = {tAvailableDCOs, tAssignedDCOs};
    ArrayLayout l = new ArrayLayout(controlsPanel); // the "north" component ("south" being the buttons)
    l.add(controls, rights, fills);
    myDialog.add(controlsPanel, BorderLayout.NORTH);
    myDialog.add(buttonsPanel, BorderLayout.SOUTH);

    JComponent controls[][] = {
    {panelAllocationPanel, 	panelAllocationPanel}
    lCollectionUnit, 		comboCollectionUnit}
    lServiceType, 		comboServiceType}
    lRegionType, 		listRegion}
    null, 			listRegion}
    panelEffectiveDate, 	panelEffectiveDate}
    }

    JComponent controls2[] = {
    {
    lServiceType, 		comboServiceType}
    panelEffectiveDate, 	panelEffectiveDate}
    }

    JComponent right[] = {lCollectionUnit, lServiceType};

    ArrayLayout l = new ArrayLayout(...);
    if(type==xxx)
    l.add(control2, right, null)
    else l.add(controls,right, null);

Constructor Summary
`ArrayLayout(javax.swing.JComponent container)` set the layout for the given container

Method Summary
`void` | `add(java.awt.Component[][] components)`
`void` | `add(java.awt.Component[][] controls, java.awt.Component[] rights, java.awt.Component[] fills)` similar to the createLayout method but this one will allow you to have access to the ArrayLayout so you can further customise the layout after it is initially created.
`void` | `add(java.awt.Component[][] controls, java.awt.Component[] rights, java.awt.Component[] fills, java.lang.String title)`
`static void` | `applyContainerStyles(javax.swing.JComponent container)` Set some defaults for a Panel.
`static void` | `centerComponent(java.awt.Component child, java.awt.Component parent)` pop the child in the middle of the parent.
`static void` | `centerComponentOnScreen(java.awt.Component f)` pop the component in the middle of the screen.
`static javax.swing.JComponent` | `createLayout(java.awt.Component[][] controls, java.awt.Component[] rights, java.awt.Component[] fills, java.lang.String title)` create a laid out component in one step.
`static java.awt.Frame` | `getFrame(java.awt.Component c)` traverse the components parents to find the frame.
`com.objexcel.gui.ArrayLayout.JGridBagLayout` | `getLayout()` get the underlying GridBagLayout to really customise the layout.
`void` | `setAnchorValues(java.awt.Component[] components, int value)` sets where the components are anchored.
`void` | `setFillValues(java.awt.Component[] components, int value)` if a field is in a column/row is wider/taller than the components' preferred sizes, gobble up the rest of the space.
`static void` | `setMnemonic(javax.swing.JComponent c, javax.swing.JLabel l, char mnemonic)` set the label and displayed mnemonic for the components
`static void` | `setTitle(java.awt.Component c, java.lang.String s)` traverse the components owners until we find the frame (including a JInternal frame) and set the title.
`void` | `setWeightXValues(java.awt.Component[] components, int value)` set the underlying GridBagLayout weight Y value.
`void` | `setWeightYValues(java.awt.Component[] components, int value)` set the underlying GridBagLayout weight Y value.

Methods inherited from class java.lang.Object
`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### ArrayLayout

    public ArrayLayout(javax.swing.JComponent container)

  set the layout for the given container

Method Detail

### createLayout

    public static javax.swing.JComponent createLayout(java.awt.Component[][] controls,
                                                      java.awt.Component[] rights,
                                                      java.awt.Component[] fills,
                                                      java.lang.String title)

  create a laid out component in one step. Only provide a title if you want group box arount the components. Controls can be repeated in a column and/or row. But the repeats have to be contiguous. e.g. controls[][] = { {a, null, a, a} } is no good but controls[][] = { {a, a, a} } will fill up 3 columns. Its ok to have nulls in the array (these represent empty space).
  Parameters:
    `controls` - the controls you want laid out
    `rights` - component you want aligned to the right. null if n/a
    `fills` - components you want to take up any space as the container get bigger

### getLayout

    public com.objexcel.gui.ArrayLayout.JGridBagLayout getLayout()

  get the underlying GridBagLayout to really customise the layout. Good luck!

### add

    public void add(java.awt.Component[][] controls,
                    java.awt.Component[] rights,
                    java.awt.Component[] fills)

  similar to the createLayout method but this one will allow you to have access to the ArrayLayout so you can further customise the layout after it is initially created.

### add

    public void add(java.awt.Component[][] controls,
                    java.awt.Component[] rights,
                    java.awt.Component[] fills,
                    java.lang.String title)

### add

    public void add(java.awt.Component[][] components)

### setWeightXValues

    public void setWeightXValues(java.awt.Component[] components,
                                 int value)

  set the underlying GridBagLayout weight Y value. i.e. if >0 will gobble up extra width

### setWeightYValues

    public void setWeightYValues(java.awt.Component[] components,
                                 int value)

  set the underlying GridBagLayout weight Y value. ie. if value > 0 gobble up any extra vertical space

### setFillValues

    public void setFillValues(java.awt.Component[] components,
                              int value)

  if a field is in a column/row is wider/taller than the components' preferred sizes, gobble up the rest of the space. The column/row however will not gobble up any extra space if its container is enlarged (you need weight XY for that)

### setAnchorValues

    public void setAnchorValues(java.awt.Component[] components,
                                int value)

  sets where the components are anchored.

### applyContainerStyles

    public static void applyContainerStyles(javax.swing.JComponent container)

  Set some defaults for a Panel. BorderLayout. 5 pixel empty border. V and H gaps of 5 pixels. This method is actually nothing to do with Array Layouts (but this class was as good a place as any to put it).

### setMnemonic

    public static void setMnemonic(javax.swing.JComponent c,
                                   javax.swing.JLabel l,
                                   char mnemonic)

  set the label and displayed mnemonic for the components

### getFrame

    public static java.awt.Frame getFrame(java.awt.Component c)

  traverse the components parents to find the frame.

### setTitle

    public static void setTitle(java.awt.Component c,
                                java.lang.String s)

  traverse the components owners until we find the frame (including a JInternal frame) and set the title.

### centerComponentOnScreen

    public static void centerComponentOnScreen(java.awt.Component f)

  pop the component in the middle of the screen.

### centerComponent

    public static void centerComponent(java.awt.Component child,
                                       java.awt.Component parent)

  pop the child in the middle of the parent.

Overview | Package | Class | Tree | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD