org.tigris.swidgets

Class LabelledLayout

Implemented Interfaces:
LayoutManager, java.io.Serializable

public class LabelledLayout
extends java.lang.Object
implements LayoutManager, java.io.Serializable

This layout manager lines up components in 2 columns. All JLabels are the first column and any component the JLabel is registered with is in a second column next to the label.

Components are sized automatically to fill available space in the container when it is resized.

All JLabel widths will be the largest of the JLabel preferred widths (unless the container is too narrow).

The components will take up any left over width unless they are restricted themselves by a maximum width.

The height of each component is either fixed or will resize to use up any available space in the container. Whether a components height is resizable is determined by checking whether the preferred height of that component is greater then its minimum height. This is the case for components such as JList which would require to expand to show the maximum number or items.

If a component is not to have its height resized then its preferred height and minimum height should be the same. This is the case for components such as JTextField and JComboBox* which should always stay the same height.

[There is known bug in JRE5 where the prefered height and minimum height of a JComboBox can differ. LabelledLayout has coded a workaround for this bug. See - http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6255154 ]

LabelledLayout can show multiple panels of label/component pairs. The seperation of these panels is indicated by adding a Seperator component to the container. Labelled layout starts a new panel when detecting this Seperator.

When there are multiple panels, each panel is given equal width. The width restriction of JLabels and components described above are then dependent on panel width rather than container width.

Author:
Bob Tarling
See Also:
Serialized Form

Constructor Summary

LabelledLayout()
Construct a new LabelledLayout.
LabelledLayout(boolean ignoreSplitters)
Construct a new LabelledLayout.
LabelledLayout(int hgap, int vgap)
Construct a new horizontal LabelledLayout with the specified cell spacing.

Method Summary

void
addLayoutComponent(String name, Component comp)
Adds the specified component with the specified name to the layout.
int
getHgap()
static org.tigris.swidgets.Seperator
getSeperator()
int
getVgap()
void
layoutContainer(Container parent)
Dimension
minimumLayoutSize(Container parent)
Required by LayoutManager.
Dimension
preferredLayoutSize(Container parent)
Determines the preferred size of the container argument using this labelled layout.
void
removeLayoutComponent(Component comp)
Removes the specified component with the specified name from the layout.
void
setHgap(int hgap)
void
setVgap(int vgap)

Constructor Details

LabelledLayout

public LabelledLayout()
Construct a new LabelledLayout.

LabelledLayout

public LabelledLayout(boolean ignoreSplitters)
Construct a new LabelledLayout.

LabelledLayout

public LabelledLayout(int hgap,
                      int vgap)
Construct a new horizontal LabelledLayout with the specified cell spacing.

Method Details

addLayoutComponent

public void addLayoutComponent(String name,
                               Component comp)
Adds the specified component with the specified name to the layout. This is included to satisfy the LayoutManager interface but is not actually used in this layout implementation.
Parameters:
name - the name of the component
comp - the component to be added

getHgap

public int getHgap()

getSeperator

public static org.tigris.swidgets.Seperator getSeperator()

getVgap

public int getVgap()

layoutContainer

public void layoutContainer(Container parent)
See Also:
java.awt.LayoutManager.layoutContainer(java.awt.Container)

minimumLayoutSize

public Dimension minimumLayoutSize(Container parent)
Required by LayoutManager.
See Also:
java.awt.LayoutManager.minimumLayoutSize(java.awt.Container)

preferredLayoutSize

public Dimension preferredLayoutSize(Container parent)
Determines the preferred size of the container argument using this labelled layout. The preferred size is that all child components are in one section at their own preferred size with gaps and border indents.

removeLayoutComponent

public void removeLayoutComponent(Component comp)
Removes the specified component with the specified name from the layout. This is included to satisfy the LayoutManager interface but is not actually used in this layout implementation.
Parameters:

setHgap

public void setHgap(int hgap)

setVgap

public void setVgap(int vgap)