MarginSpaceProperties.java Source code

Java tutorial

Introduction

Here is the source code for MarginSpaceProperties.java

Source

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class MarginSpaceProperties {
    public static void main(String[] args) {
        Display display = new Display();
        final Shell shell = new Shell(display);

        FillLayout fillLayout = new FillLayout(SWT.HORIZONTAL);

        // Width of horizontal margins placed along the left and right edges    
        fillLayout.marginWidth = 5;
        // Height of vertical margins placed along the top and bottom edges
        fillLayout.marginHeight = 5;

        shell.setLayout(fillLayout);

        Button button1 = new Button(shell, SWT.PUSH);
        button1.setText("button1");

        Button button2 = new Button(shell, SWT.PUSH);
        button2.setText("button number 2");

        Button button3 = new Button(shell, SWT.PUSH);
        button3.setText("3");

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

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