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 FormLayoutAttachEachOther {
public static void main(String[] args) {
final Display display = new Display();
final Shell shell = new Shell(display, SWT.SHELL_TRIM);
shell.setLayout(new FormLayout());
Button button1 = new Button(shell, SWT.PUSH);
button1.setText("button1");
FormData formData = new FormData();
formData.left = new FormAttachment(20);
formData.top = new FormAttachment(20);
button1.setLayoutData(formData);
Button button2 = new Button(shell, SWT.PUSH);
button2.setText("button number 2");
formData = new FormData();
formData.left = new FormAttachment(button1, 0, SWT.CENTER);
formData.top = new FormAttachment(button1, 0, SWT.CENTER);
button2.setLayoutData(formData);
shell.pack();
shell.open();
// Set up the event loop.
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
// If no more entries in event queue
display.sleep();
}
}
display.dispose();
}
}
|