The following constants are possible values for the alignment property:
- org.eclipse.swt.SWT.TOP: to the top side of the specified control
- org.eclipse.swt.SWT.TOP is for top and bottom alignments only.
- org.eclipse.swt.SWT.BOTTOM: to the bottom side of the specified control.
- org.eclipse.swt.SWT.BOTTOM is for top and bottom alignments only.
- org.eclipse.swt.SWT.LEFT: to the left side of the specified control.
- org.eclipse.swt.SWT.LEFT is for left and right alignments only.
- org.eclipse.swt.SWT.RIGHT: to the right side of the specified control.
- org.eclipse.swt.SWT.RIGHT is for left and right alignments only.
- org.eclipse.swt.SWT.CENTER: center the control on the specified control.
- org.eclipse.swt.SWT.DEFAULT: to the adjacent side of the specified control.
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class FormLayoutAnotherControl {
public static void main(String[] args) {
Display display = new Display();
final Shell shell = new Shell(display);
shell.setLayout(new FormLayout());
Button button1 = new Button(shell, SWT.PUSH);
button1.setText("button1");
Button button2 = new Button(shell, SWT.PUSH);
button2.setText("button2");
FormData formData = new FormData();
formData.left = new FormAttachment(button1);
button2.setLayoutData(formData);
Button button3 = new Button(shell, SWT.PUSH);
button3.setText("button3");
formData = new FormData();
formData.top = new FormAttachment(button2, 10);
formData.left = new FormAttachment(button2, 0, SWT.LEFT);
button3.setLayoutData(formData);
shell.setSize(450, 400);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
}