FormLayout.
FormAttachments are set into the top, bottom, left,
and right fields of the FormData for a control.
For example:
FormData data = new FormData(); data.top = new FormAttachment(0,5); data.bottom = new FormAttachment(100,-5); data.left = new FormAttachment(0,5); data.right = new FormAttachment(100,-5); button.setLayoutData(data);
A FormAttachment defines where to attach the side of
a control by using the equation, y = ax + b. The "a" term represents
a fraction of the parent composite's width (from the left) or height
(from the top). It can be defined using a numerator and denominator,
or just a percentage value. If a percentage is used, the denominator
is set to 100. The "b" term in the equation represents an offset, in
points, from the attachment position. For example:
FormAttachment attach = new FormAttachment (20, -5);
specifies that the side to which the FormAttachment
object belongs will lie at 20% of the parent composite, minus 5 points.
Control sides can also be attached to another control. For example:
FormAttachment attach = new FormAttachment (button, 10);specifies that the side to which the
FormAttachment
object belongs will lie in the same position as the adjacent side of
the button control, plus 10 points. The control side can
also be attached to the opposite side of the specified control.
For example:
FormData data = new FormData (); data.left = new FormAttachment (button, 0, SWT.LEFT);specifies that the left side of the control will lie in the same position as the left side of the
button control. The control can also
be attached in a position that will center the control on the specified
control. For example:
data.left = new FormAttachment (button, 0, SWT.CENTER);specifies that the left side of the control will be positioned so that it is centered between the left and right sides of the
button control.
If the alignment is not specified, the default is to attach to the adjacent side.
FormLayout, FormData, Sample code and further information
| Modifier and Type | Field and Description |
|---|---|
| public int | alignment
alignment specifies the alignment of the control side that is attached to a control. |
| public Control | control
control specifies the control to which the control side is attached. |
| public int | denominator
denominator specifies the denominator of the "a" term in the equation, y = ax + b, which defines the attachment. |
| public int | numerator
numerator specifies the numerator of the "a" term in the equation, y = ax + b, which defines the attachment. |
| public int | offset
offset specifies the offset, in points, of the control side from the attachment position. |
| Access | Constructor and Description |
|---|---|
| public | |
| public | FormAttachment(int
the percentage of the position numerator)Constructs a new instance of this class given a numerator Since no denominator or offset is specified, the default is to treat the numerator as a percentage of the form, with a denominator of 100. |
| public | FormAttachment(int
the percentage of the position numerator, int the offset of the side from the position offset)Constructs a new instance of this class given a numerator and an offset. |
| public | FormAttachment(int
the numerator of the position numerator, int the denominator of the position denominator, int the offset of the side from the position offset)Constructs a new instance of this class given a numerator and denominator and an offset. |
| public | FormAttachment(Control
the control the side is attached to control)Constructs a new instance of this class given a control. |
| public | FormAttachment(Control
the control the side is attached to control, int the offset of the side from the control offset)Constructs a new instance of this class given a control and an offset. |
| public | FormAttachment(Control
the control the side is attached to control, int the offset of the side from the control offset, int the alignment of the side to the control it is attached to,
one of TOP, BOTTOM, LEFT, RIGHT, CENTER, or DEFAULT alignment)Constructs a new instance of this class given a control, an offset and an alignment. |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv FormAttachment | |
| pack-priv int | |
| pack-priv FormAttachment | |
| pack-priv FormAttachment | |
| pack-priv FormAttachment | |
| pack-priv FormAttachment | |
| pack-priv int | |
| pack-priv int | |
| public String | Returns: a string representation of the FormAttachmentOverrides java. |
| alignment | back to summary |
|---|---|
| public int alignment alignment specifies the alignment of the control side that is attached to a control. For top and bottom attachments, TOP, BOTTOM and CENTER are used. For left and right attachments, LEFT, RIGHT and CENTER are used. If any other case occurs, the default will be used instead. Possible values are:
| |
| control | back to summary |
|---|---|
| public Control control control specifies the control to which the control side is attached. | |
| denominator | back to summary |
|---|---|
| public int denominator denominator specifies the denominator of the "a" term in the equation, y = ax + b, which defines the attachment. The default value is 100. | |
| numerator | back to summary |
|---|---|
| public int numerator numerator specifies the numerator of the "a" term in the equation, y = ax + b, which defines the attachment. | |
| offset | back to summary |
|---|---|
| public int offset offset specifies the offset, in points, of the control side from the attachment position. If the offset is positive, then the control side is offset to the right of or below the attachment position. If it is negative, then the control side is offset to the left of or above the attachment position. This is equivalent to the "b" term in the equation y = ax + b. The default value is 0. | |
| FormAttachment | back to summary |
|---|---|
| public FormAttachment() Constructs a new instance of this class. Since no numerator, denominator or offset is specified, the attachment is treated as a percentage of the form. The numerator is zero, the denominator is 100 and the offset is zero.
| |
| FormAttachment | back to summary |
|---|---|
| public FormAttachment(int numerator) Constructs a new instance of this class given a numerator Since no denominator or offset is specified, the default is to treat the numerator as a percentage of the form, with a denominator of 100. The offset is zero.
| |
| FormAttachment | back to summary |
|---|---|
| public FormAttachment(int numerator, int offset) Constructs a new instance of this class given a numerator and an offset. Since no denominator is specified, the default is to treat the numerator as a percentage of the form, with a denominator of 100.
| |
| FormAttachment | back to summary |
|---|---|
| public FormAttachment(int numerator, int denominator, int offset) Constructs a new instance of this class given a numerator and denominator and an offset. The position of the side is given by the fraction of the form defined by the numerator and denominator.
| |
| FormAttachment | back to summary |
|---|---|
| public FormAttachment(Control control) Constructs a new instance of this class given a control. Since no alignment is specified, the default alignment is to attach the side to the adjacent side of the specified control. Since no offset is specified, an offset of 0 is used.
| |
| FormAttachment | back to summary |
|---|---|
| public FormAttachment(Control control, int offset) Constructs a new instance of this class given a control and an offset. Since no alignment is specified, the default alignment is to attach the side to the adjacent side of the specified control.
| |
| FormAttachment | back to summary |
|---|---|
| public FormAttachment(Control control, int offset, int alignment) Constructs a new instance of this class given a control, an offset and an alignment. The possible alignment values are:
| |
| divide | back to summary |
|---|---|
| pack-priv FormAttachment divide(int value) | |
| gcd | back to summary |
|---|---|
| pack-priv int gcd(int m, int n) | |
| minus | back to summary |
|---|---|
| pack-priv FormAttachment minus(FormAttachment attachment) | |
| minus | back to summary |
|---|---|
| pack-priv FormAttachment minus(int value) | |
| plus | back to summary |
|---|---|
| pack-priv FormAttachment plus(FormAttachment attachment) | |
| plus | back to summary |
|---|---|
| pack-priv FormAttachment plus(int value) | |
| solveX | back to summary |
|---|---|
| pack-priv int solveX(int value) | |
| solveY | back to summary |
|---|---|
| pack-priv int solveY(int value) | |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Returns a string containing a concise, human-readable description of the receiver. | |