MainClass.java Source code

Java tutorial

Introduction

Here is the source code for MainClass.java

Source

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class MainClass {

    public static void main(String[] a) {

        final Display d = new Display();
        final Shell shell = new Shell(d);

        shell.setSize(250, 200);

        shell.setLayout(new GridLayout(1, false));

        Composite buttonBar = new Composite(shell, SWT.NONE);
        buttonBar.setLayout(new RowLayout());
        Button flip = new Button(buttonBar, SWT.PUSH);
        flip.setText("Switch Orientation");
        Button weights = new Button(buttonBar, SWT.PUSH);
        weights.setText("Restore Weights");

        Composite sash = new Composite(shell, SWT.NONE);
        sash.setLayout(new FillLayout());
        sash.setLayoutData(new GridData(GridData.FILL_BOTH));
        final SashForm sashForm = new SashForm(sash, SWT.HORIZONTAL);

        sashForm.SASH_WIDTH = 5;

        sashForm.setBackground(shell.getDisplay().getSystemColor(SWT.COLOR_WHITE));

        final Button one = new Button(sashForm, SWT.PUSH);
        one.setText("One");

        final Button two = new Button(sashForm, SWT.PUSH);
        two.setText("Two");

        final Button three = new Button(sashForm, SWT.PUSH);
        three.setText("Three");

        sashForm.setWeights(new int[] { 2, 2, 2 });

        flip.addSelectionListener(new SelectionAdapter() {
            public void widgetSelected(SelectionEvent event) {
                switch (sashForm.getOrientation()) {
                case SWT.HORIZONTAL:
                    sashForm.setOrientation(SWT.VERTICAL);
                    break;
                case SWT.VERTICAL:
                    sashForm.setOrientation(SWT.HORIZONTAL);
                    break;
                }
            }
        });

        weights.addSelectionListener(new SelectionAdapter() {
            public void widgetSelected(SelectionEvent event) {
                sashForm.setWeights(new int[] { 2, 2, 2 });
            }
        });

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

}