Logo Search packages:      
Sourcecode: libjgoodies-forms-java version File versions  Download package

com::jgoodies::forms::layout::FormLayout Class Reference

Inherits java::awt::LayoutManager2, and java::io::Serializable.

List of all members.

Detailed Description

FormLayout is a powerful, flexible and precise general purpose layout manager. It aligns components vertically and horizontally in a dynamic rectangular grid of cells, with each component occupying one or more cells. A whitepaper about the FormLayout ships with the product documentation and is available online.

To use FormLayout you first define the grid by specifying the columns and rows. In a second step you add components to the grid. You can specify columns and rows via human-readable String descriptions or via arrays of ColumnSpec and RowSpec instances.

Each component managed by a FormLayout is associated with an instance of CellConstraints. The constraints object specifies where a component should be located on the form's grid and how the component should be positioned. In addition to its constraints object the FormLayout also considers each component's minimum and preferred sizes in order to determine a component's size.

FormLayout has been designed to work with non-visual builders that help you specify the layout and fill the grid. For example, the com.jgoodies.forms.builder.ButtonBarBuilder assists you in building button bars; it creates a standardized FormLayout and provides a minimal API that specializes in adding buttons. Other builders can create frequently used panel design, for example a form that consists of rows of label-component pairs.

FormLayout has been prepared to work with different types of sizes as defined by the Size interface.

Example 1 (Plain FormLayout):
The following example creates a panel with 3 data columns and 3 data rows; the columns and rows are specified before components are added to the form.

 FormLayout layout = new FormLayout(
      "right:pref, 6dlu, 50dlu, 4dlu, default",  // columns 
      "pref, 3dlu, pref, 3dlu, pref");           // rows

 CellConstraints cc = new CellConstraints();
 JPanel panel = new JPanel(layout);
 panel.add(new JLabel("Label1"),   cc.xy  (1, 1));
 panel.add(new JTextField(),       cc.xywh(3, 1, 3, 1));
 panel.add(new JLabel("Label2"),   cc.xy  (1, 3));
 panel.add(new JTextField(),       cc.xy  (3, 3));
 panel.add(new JLabel("Label3"),   cc.xy  (1, 5));
 panel.add(new JTextField(),       cc.xy  (3, 5));
 panel.add(new JButton("..."),     cc.xy  (5, 5));
 return panel;

Example 2 (Using PanelBuilder):
This example creates the same panel as above using the com.jgoodies.forms.builder.PanelBuilder to add components to the form.

 FormLayout layout = new FormLayout(
      "right:pref, 6dlu, 50dlu, 4dlu, default",  // columns 
      "pref, 3dlu, pref, 3dlu, pref");           // rows

 PanelBuilder builder = new PanelBuilder(layout);
 CellConstraints cc = new CellConstraints();
 builder.addLabel("Label1",        cc.xy  (1, 1));
 builder.add(new JTextField(),     cc.xywh(3, 1, 3, 1));
 builder.addLabel("Label2",        cc.xy  (1, 3));
 builder.add(new JTextField(),     cc.xy  (3, 3));
 builder.addLabel("Label3",        cc.xy  (1, 5));
 builder.add(new JTextField(),     cc.xy  (3, 5));
 builder.add(new JButton("..."),   cc.xy  (5, 5));
 return builder.getPanel();

Example 3 (Using DefaultFormBuilder):
This example utilizes the com.jgoodies.forms.builder.DefaultFormBuilder that ships with the source distribution.

 FormLayout layout = new FormLayout(
      "right:pref, 6dlu, 50dlu, 4dlu, default",  // columns 
      "");                                       // add rows dynamically

 DefaultFormBuilder builder = new DefaultFormBuilder(layout);
 builder.append("Label1", new JTextField(), 3);
 builder.append("Label2", new JTextField());
 builder.append("Label3", new JTextField());
 builder.append(new JButton("..."));
 return builder.getPanel();

Karsten Lentzsch

See also:









Definition at line 149 of file FormLayout.java.

Public Member Functions

void addGroupedColumn (int columnIndex)
void addGroupedRow (int rowIndex)
void addLayoutComponent (Component comp, Object constraints)
void addLayoutComponent (String name, Component component)
void appendColumn (ColumnSpec columnSpec)
void appendRow (RowSpec rowSpec)
 FormLayout (String encodedColumnSpecs)
 FormLayout (String encodedColumnSpecs, String encodedRowSpecs)
 FormLayout (ColumnSpec[] colSpecs, RowSpec[] rowSpecs)
int getColumnCount ()
int[][] getColumnGroups ()
ColumnSpec getColumnSpec (int columnIndex)
CellConstraints getConstraints (Component component)
float getLayoutAlignmentX (Container parent)
float getLayoutAlignmentY (Container parent)
LayoutInfo getLayoutInfo (Container parent)
int getRowCount ()
int[][] getRowGroups ()
RowSpec getRowSpec (int rowIndex)
void insertColumn (int columnIndex, ColumnSpec columnSpec)
void insertRow (int rowIndex, RowSpec rowSpec)
void invalidateLayout (Container target)
void layoutContainer (Container parent)
Dimension maximumLayoutSize (Container target)
Dimension minimumLayoutSize (Container parent)
Dimension preferredLayoutSize (Container parent)
void removeColumn (int columnIndex)
void removeLayoutComponent (Component comp)
void removeRow (int rowIndex)
void setColumnGroups (int[][] colGroupIndices)
void setColumnSpec (int columnIndex, ColumnSpec columnSpec)
void setConstraints (Component component, CellConstraints constraints)
void setRowGroups (int[][] rowGroupIndices)
void setRowSpec (int rowIndex, RowSpec rowSpec)

Private Member Functions

void adjustGroupIndices (int[][] allGroupIndices, int modifiedIndex, boolean remove)
int[] compressedSizes (List formSpecs, int totalSize, int totalMinSize, int totalPrefSize, int[] minSizes, int[] prefSizes)
int[] computeGridOrigins (Container container, int totalSize, int offset, List formSpecs, List[] componentLists, int[][] groupIndices, Measure minMeasure, Measure prefMeasure)
Dimension computeLayoutSize (Container parent, Measure defaultWidthMeasure, Measure defaultHeightMeasure)
int[] computeMaximumFixedSpanTable (List formSpecs)
int[] computeOrigins (int[] sizes, int offset)
int[][] deepClone (int[][] array)
int[] distributedSizes (List formSpecs, int totalSize, int totalPrefSize, int[] inputSizes)
int[] groupedSizes (int[][] groups, int[] rawSizes)
void initializeColAndRowComponentLists ()
void invalidateCaches ()
void layoutComponents (int[] x, int[] y)
int[] maximumSizes (Container container, List formSpecs, List[] componentLists, Measure minMeasure, Measure prefMeasure, Measure defaultMeasure)
void removeConstraints (Component component)
void shiftComponentsHorizontally (int columnIndex, boolean remove)
void shiftComponentsVertically (int rowIndex, boolean remove)
int sum (int[] sizes)
void writeObject (ObjectOutputStream out) throws IOException

Private Attributes

transient List[] colComponents
int[][] colGroupIndices
final List colSpecs
final ComponentSizeCache componentSizeCache
final Map constraintMap
final Measure minimumHeightMeasure
final Measure minimumWidthMeasure
final Measure preferredHeightMeasure
final Measure preferredWidthMeasure
transient List[] rowComponents
int[][] rowGroupIndices
final List rowSpecs


class  CachingMeasure
class  ComponentSizeCache
class  LayoutInfo
interface  Measure
class  MinimumHeightMeasure
class  MinimumWidthMeasure
class  PreferredHeightMeasure
class  PreferredWidthMeasure

The documentation for this class was generated from the following file:

Generated by  Doxygen 1.6.0   Back to index