net.sf.simplelayout
Class SimpleLayout

java.lang.Object
  extended by net.sf.simplelayout.SimpleLayout
All Implemented Interfaces:
java.awt.LayoutManager

public class SimpleLayout
extends java.lang.Object
implements java.awt.LayoutManager

Simple Layout Manager which organizes its components in columns and rows. Per default, there are 2 columns. The components are just added in the right order. You can specify how the columns are aligned, by setting the row constraints. Example:

 SimpleLayout layout = new SimpleLayout();
 // align the labels to the right
 layout.setAlignment(0, SimpleLayout.RIGHT);
 JPanel panel = new JPanel(layout);
 
 panel.add(new JLabel("Name"));
 panel.add(new JTextField()); // Textfield 1
 panel.add(new JLabel("Street"));
 panel.add(new JTextField()); // Textfield 2
 
This creates a Panel with two rows and two columns. The labels are put in the first column, the text fields in the second:
Name Textfield 1
StreetTextfield 2

Author:
Claus Radloff

Field Summary
static SimpleLayoutConstraints CENTER
          put the components in the center corner
static SimpleLayoutConstraints EAST
          put the components center right corner
static SimpleLayoutConstraints NORTH
          put the components top center corner
static SimpleLayoutConstraints NORTHEAST
          put the components top right corner
static SimpleLayoutConstraints NORTHWEST
          put the components top left corner (default)
static SimpleLayoutConstraints SOUTH
          put the components lower center corner
static SimpleLayoutConstraints SOUTHEAST
          put the components lower right corner
static SimpleLayoutConstraints SOUTHWEST
          put the components lower left corner
static SimpleLayoutConstraints WEST
          put the components center left corner
 
Constructor Summary
SimpleLayout()
          Constructor with two columns and no gaps.
SimpleLayout(int columns)
          Constructor with no gaps.
SimpleLayout(int columns, int hgap, int vgap)
          Constructor with no gaps.
 
Method Summary
 void addLayoutComponent(java.lang.String name, java.awt.Component c)
          Do nothing.
 int getHgap()
          Returns the horizontal gap between components.
 int getVgap()
          Returns the vertical gap between components.
 void layoutContainer(java.awt.Container parent)
          Lays out the specified container.
 java.awt.Dimension maximumLayoutSize(java.awt.Container parent)
          Calculates the maximum size dimensions for the specified container, given the components it contains.
 java.awt.Dimension minimumLayoutSize(java.awt.Container parent)
          Calculates the minimum size dimensions for the specified container, given the components it contains.
 java.awt.Dimension preferredLayoutSize(java.awt.Container parent)
          Calculates the preferred size dimensions for the specified container, given the components it contains.
 void removeLayoutComponent(java.awt.Component c)
          Do nothing.
 void setAlignment(int col, SimpleLayoutConstraints align)
          Set the alignment for the given column.
 void setHgap(int hgap)
          Sets the horizontal gap between components.
 void setVgap(int vgap)
          Sets the vertical gap between components.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NORTH

public static final SimpleLayoutConstraints NORTH
put the components top center corner


NORTHEAST

public static final SimpleLayoutConstraints NORTHEAST
put the components top right corner


EAST

public static final SimpleLayoutConstraints EAST
put the components center right corner


SOUTHEAST

public static final SimpleLayoutConstraints SOUTHEAST
put the components lower right corner


SOUTH

public static final SimpleLayoutConstraints SOUTH
put the components lower center corner


SOUTHWEST

public static final SimpleLayoutConstraints SOUTHWEST
put the components lower left corner


WEST

public static final SimpleLayoutConstraints WEST
put the components center left corner


NORTHWEST

public static final SimpleLayoutConstraints NORTHWEST
put the components top left corner (default)


CENTER

public static final SimpleLayoutConstraints CENTER
put the components in the center corner

Constructor Detail

SimpleLayout

public SimpleLayout()
Constructor with two columns and no gaps.


SimpleLayout

public SimpleLayout(int columns)
Constructor with no gaps.

Parameters:
columns - number of columns

SimpleLayout

public SimpleLayout(int columns,
                    int hgap,
                    int vgap)
Constructor with no gaps.

Parameters:
columns - number of columns
hgap - horizontal gap
vgap - vertical gap
Method Detail

addLayoutComponent

public void addLayoutComponent(java.lang.String name,
                               java.awt.Component c)
Do nothing.

Specified by:
addLayoutComponent in interface java.awt.LayoutManager
Parameters:
name - unused
c - unused
See Also:
LayoutManager.addLayoutComponent(java.lang.String, java.awt.Component)

getHgap

public int getHgap()
Returns the horizontal gap between components.

Returns:
horizontal gap

getVgap

public int getVgap()
Returns the vertical gap between components.

Returns:
vertical gap

layoutContainer

public void layoutContainer(java.awt.Container parent)
Lays out the specified container.

Specified by:
layoutContainer in interface java.awt.LayoutManager
See Also:
LayoutManager.layoutContainer(java.awt.Container)

maximumLayoutSize

public java.awt.Dimension maximumLayoutSize(java.awt.Container parent)
Calculates the maximum size dimensions for the specified container, given the components it contains.

Parameters:
parent - parent container
Returns:
the dimension

minimumLayoutSize

public java.awt.Dimension minimumLayoutSize(java.awt.Container parent)
Calculates the minimum size dimensions for the specified container, given the components it contains.

Specified by:
minimumLayoutSize in interface java.awt.LayoutManager
Parameters:
parent - parent container
Returns:
the dimension
See Also:
LayoutManager.minimumLayoutSize(java.awt.Container)

preferredLayoutSize

public java.awt.Dimension preferredLayoutSize(java.awt.Container parent)
Calculates the preferred size dimensions for the specified container, given the components it contains.

Specified by:
preferredLayoutSize in interface java.awt.LayoutManager
See Also:
LayoutManager.preferredLayoutSize(java.awt.Container)

removeLayoutComponent

public void removeLayoutComponent(java.awt.Component c)
Do nothing.

Specified by:
removeLayoutComponent in interface java.awt.LayoutManager
See Also:
LayoutManager.removeLayoutComponent(java.awt.Component)

setAlignment

public void setAlignment(int col,
                         SimpleLayoutConstraints align)
Set the alignment for the given column.

Parameters:
col - the column to set the alignment for
align - the alignment

setHgap

public void setHgap(int hgap)
Sets the horizontal gap between components.

Parameters:
hgap - the horizontal gap between components

setVgap

public void setVgap(int vgap)
Sets the vertical gap between components.

Parameters:
vgap - the vertical gap between components