Form Layout


FormLayout is a Java LayoutManager that resembles the Motif XmFormWidget behavor. For every edge (side) of a component, you can assign an attachment. These attachments can be to the Container or to another Component. The attachments determine the layout behavior of the Component when resizing occurs.


How it works

Create a Container and set an instance of the FormLayout as the layout manager. The constructor of a FormLayout will automatically assign itself as the layout manager to the Container supplied in the instatiation.

FormLayout form = new FormLayout (cont);

After a component is added to a container, you can assign the attachments with a call to form.constrain. Every call to constrain looks like this

constrain (Component, Edge, Attachment, Target, Offset);
Parameter Explanation
Component Component to assign attachments to
Edge FormLayout.TOP
Attachment FormLayout.ATTACH_NONE
Offset Offset from the target or container side


Attachment Explanation
ATTACH_NONE Edge does not have any constraint.
ATTACH_FORM Edge is layed out Offset pixels from the side of the Container.
ATTACH_COMPONENT Edge is layed out Offset pixels from Target.
ATTACH_OPPOSITE_COMPONENT Edge is layed out Offset pixels from the opposite side of Target.
ATTACH_CENTER Component is centered with respect to Target. If Target is null, then Component is centered on the Container.


Differences from XmForm

Aside from the fact that FormLayout does not implement all of the XmForm functionality, FormLayout does have extended functionality beyond XmForm. Unlike XmForm, FormLayout will allow Components to have contraints relative to each other as long as they are not truely circular. In other words, Component A can be attached to the left of Component B and Component B can be attached to the bottom of Component A. Similiarly, Component A can be attached to itself. This can be used to specify a fixed width or height for a component. Lastly, FormLayout supports centering.