FormLayout lays out widgets using an attachment model. A FormAttachment can be defined for each side of a widget and stored in its layout data (FormData). The FormData can be used to designate a requested width and height for the widget, provided that these values do not conflict with the attachment constraints.
A FormAttachment is used to attach a designated side of the widget to the parent Composite or another widget in the layout. You typically do not set attachments on all sides of a widget. It is very common to specify only one horizontal (left or right) attachment and one vertical (top or bottom) attachment and allow the widgets to take the size specified in their FormData, or their preferred size if no size is specified in the FormData.
Attachments can be configured in a variety of ways:
The following table summarizes the attributes of a FormLayout:
Attribute |
Description |
---|---|
marginHeight |
Specifies the number of pixels of vertical margin that will be placed along the top and bottom edges of the layout. |
marginWidth |
Specifies the number of pixels of horizontal margin that will be placed along the left and right edges of the layout. |
The following table summarizes the attributes of a FormData:
Attribute |
Description |
---|---|
top |
Specifies the attachment for the top side of the control. |
left |
Specifies the attachment for the left side of the control. |
bottom | Specifies the attachment for the bottom side of the control. |
right | Specifies the attachment for the right side of the control. |
width | Specifies the preferred width in pixels of the control in the form. |
height | Specifies the preferred height in pixels of the control in the form. |
The following table summarizes the attributes of a FormAttachment:
Attribute |
Description |
---|---|
alignment |
Specifies the alignment of the control side that is attached to a control. DEFAULT indicates that the widget should be attached to the adjacent side of the specified control. For top and bottom attachments, TOP, BOTTOM, and CENTER are used to indicate attachment of the specified side of the widget to the specified side of the control. For left and right attachments, LEFT, RIGHT, and CENTER are used to indicate attachment of the specified side of the widget to the specified side of the control. (For example, using TOP indicates that the top side of the attachment's widget should be attached to the top side of the specified control.) |
control |
Specifies the target control to which the attachment's widget is attached. |
denominator | Specifies the denominator of the "a" term in the equation, y=ax+b, which defines the attachment. |
numerator | Specifies the numerator of the "a" term in the equation y=ax+b, which defines the attachment. |
offset | Specifies the offset in pixels of the control side from the attachment position. Can be positive or negative. This is the "b" term in the equation y=ax+b, which defines the attachment. |
See Understanding layouts in SWT for further descriptions and example screen captures using the various attachment styles.