FormLayoutAttachFourSidesControl.java Source code

Java tutorial

Introduction

Here is the source code for FormLayoutAttachFourSidesControl.java

Source

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 FormLayoutAttachFourSidesControl {
    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");

        FormData formData = new FormData();
        formData.left = new FormAttachment(50);
        formData.right = new FormAttachment(100);
        formData.top = new FormAttachment(50);
        formData.bottom = new FormAttachment(100);

        button1.setLayoutData(formData);

        shell.setSize(450, 400);
        shell.open();

        while (!shell.isDisposed()) {
            if (!display.readAndDispatch()) {
                display.sleep();
            }
        }
        display.dispose();
    }
}