Example usage for org.eclipse.swt.widgets Button setLayoutData

List of usage examples for org.eclipse.swt.widgets Button setLayoutData

Introduction

In this page you can find the example usage for org.eclipse.swt.widgets Button setLayoutData.

Prototype

public void setLayoutData(Object layoutData) 

Source Link

Document

Sets the layout data associated with the receiver to the argument.

Usage

From source file:GridLayoutVerticalAlignment.java

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

    GridLayout gridLayout = new GridLayout();
    gridLayout.numColumns = 2;/* ww  w  . ja  v a 2 s. c  o  m*/
    gridLayout.makeColumnsEqualWidth = true;

    shell.setLayout(gridLayout);

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

    List list = new List(shell, SWT.BORDER);
    list.add("item 1");
    list.add("item 2");
    list.add("item 3");
    list.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_CENTER));

    Button button2 = new Button(shell, SWT.PUSH);
    button2.setText("button #2");
    button2.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_END));

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

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

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

From source file:GridLayoutAlignmentHoriVerical.java

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

    GridLayout gridLayout = new GridLayout();
    gridLayout.numColumns = 2;/*w w w  . j  av  a 2  s . c  o m*/
    gridLayout.makeColumnsEqualWidth = true;

    shell.setLayout(gridLayout);

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

    List list = new List(shell, SWT.BORDER);
    list.add("item 1");
    list.add("item 2");
    list.add("item 3");
    list.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER));

    Button button2 = new Button(shell, SWT.PUSH);
    button2.setText("button #2");
    button2.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));

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

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

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

From source file:GridLayoutGrabExpressionSpace.java

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

    GridLayout gridLayout = new GridLayout();
    gridLayout.numColumns = 2;/*from   w ww .j  a v a 2  s. c om*/
    gridLayout.makeColumnsEqualWidth = true;

    shell.setLayout(gridLayout);

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

    List list = new List(shell, SWT.BORDER);
    list.add("item 1");
    list.add("item 2");
    list.add("item 3");
    GridData gridData = new GridData();
    gridData.grabExcessHorizontalSpace = true;
    gridData.horizontalAlignment = GridData.FILL;
    list.setLayoutData(gridData);

    Button button2 = new Button(shell, SWT.PUSH);
    button2.setText("button #2");
    button2.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_END));

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

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

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

From source file:GridLayoutIndentation.java

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

    GridLayout gridLayout = new GridLayout();
    gridLayout.numColumns = 2;//from  ww w  . ja va 2  s . co m
    gridLayout.makeColumnsEqualWidth = true;

    shell.setLayout(gridLayout);

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

    List list = new List(shell, SWT.BORDER);
    list.add("item 1");
    list.add("item 2");
    list.add("item 3");
    list.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_CENTER));

    Button button2 = new Button(shell, SWT.PUSH);
    button2.setText("button #2");
    button2.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_END));

    Button button3 = new Button(shell, SWT.PUSH);
    button3.setText("3");
    GridData gridData = new GridData(GridData.VERTICAL_ALIGN_END);
    gridData.horizontalIndent = 50;
    button2.setLayoutData(gridData);

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

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

From source file:org.eclipse.swt.snippets.Snippet299.java

public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("Snippet 299");
    RowLayout layout = new RowLayout();
    layout.center = true;/*w  ww  .  ja  va 2 s . c om*/
    shell.setLayout(layout);

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

    Button button1 = new Button(shell, SWT.PUSH);
    button1.setText("Button 1");
    button1.setLayoutData(new RowData(SWT.DEFAULT, 50));

    Button button2 = new Button(shell, SWT.PUSH);
    button2.setText("Button 2");
    button2.setLayoutData(new RowData(SWT.DEFAULT, 70));

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

    shell.pack();
    shell.open();

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

From source file:GridLayoutSpanVeriticalHorizontal.java

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

    GridLayout gridLayout = new GridLayout();
    gridLayout.numColumns = 2;/*w ww .j a  va  2 s  .  c  o  m*/
    gridLayout.makeColumnsEqualWidth = true;

    shell.setLayout(gridLayout);

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

    List list = new List(shell, SWT.BORDER);
    list.add("item 1");
    list.add("item 2");
    list.add("item 3");
    list.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_CENTER));

    Button button2 = new Button(shell, SWT.PUSH);
    button2.setText("button #2");
    button2.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_END));

    Button button3 = new Button(shell, SWT.PUSH);
    button3.setText("3");
    GridData gridData = new GridData(GridData.VERTICAL_ALIGN_END);
    gridData.horizontalSpan = 2;
    gridData.horizontalAlignment = GridData.FILL;
    button2.setLayoutData(gridData);

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

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

From source file:org.eclipse.swt.snippets.Snippet251.java

public static void main(String[] args) {
    Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("Snippet 251");
    shell.setLayout(new FillLayout());

    Button open = new Button(shell, SWT.PUSH);
    open.setText("Open Dialog");
    open.addSelectionListener(widgetSelectedAdapter(e -> {
        final Shell dialog = new Shell(shell, SWT.DIALOG_TRIM);
        dialog.setLayout(new GridLayout(3, false));

        final DateTime calendar = new DateTime(dialog, SWT.CALENDAR | SWT.BORDER);
        final DateTime date = new DateTime(dialog, SWT.DATE | SWT.SHORT);
        final DateTime time = new DateTime(dialog, SWT.TIME | SWT.SHORT);

        new Label(dialog, SWT.NONE);
        new Label(dialog, SWT.NONE);
        Button ok = new Button(dialog, SWT.PUSH);
        ok.setText("OK");
        ok.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
        ok.addSelectionListener(widgetSelectedAdapter(event -> {
            System.out.println("Calendar date selected (MM/DD/YYYY) = " + (calendar.getMonth() + 1) + "/"
                    + calendar.getDay() + "/" + calendar.getYear());
            System.out.println("Date selected (MM/YYYY) = " + (date.getMonth() + 1) + "/" + date.getYear());
            System.out.println("Time selected (HH:MM) = " + time.getHours() + ":"
                    + (time.getMinutes() < 10 ? "0" : "") + time.getMinutes());
            dialog.close();/*  w  ww.  j  a v  a  2s . c om*/
        }));
        dialog.setDefaultButton(ok);
        dialog.pack();
        dialog.open();
    }));
    shell.pack();
    shell.open();

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

From source file:Snippet251.java

public static void main(String[] args) {
    Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());

    Button open = new Button(shell, SWT.PUSH);
    open.setText("Open Dialog");
    open.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            final Shell dialog = new Shell(shell, SWT.DIALOG_TRIM);
            dialog.setLayout(new GridLayout(3, false));

            final DateTime calendar = new DateTime(dialog, SWT.CALENDAR | SWT.BORDER);
            final DateTime date = new DateTime(dialog, SWT.DATE | SWT.SHORT);
            final DateTime time = new DateTime(dialog, SWT.TIME | SWT.SHORT);

            new Label(dialog, SWT.NONE);
            new Label(dialog, SWT.NONE);
            Button ok = new Button(dialog, SWT.PUSH);
            ok.setText("OK");
            ok.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
            ok.addSelectionListener(new SelectionAdapter() {
                public void widgetSelected(SelectionEvent e) {
                    System.out.println("Calendar date selected (MM/DD/YYYY) = " + (calendar.getMonth() + 1)
                            + "/" + calendar.getDay() + "/" + calendar.getYear());
                    System.out.println(
                            "Date selected (MM/YYYY) = " + (date.getMonth() + 1) + "/" + date.getYear());
                    System.out.println("Time selected (HH:MM) = " + time.getHours() + ":" + time.getMinutes());
                    dialog.close();/*from   w w  w.ja v  a2  s .  co m*/
                }
            });
            dialog.setDefaultButton(ok);
            dialog.pack();
            dialog.open();
        }
    });
    shell.pack();
    shell.open();

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

From source file:GridLayoutComplex.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    GridLayout layout = new GridLayout();
    layout.numColumns = 3;/*w  w  w  .  j  a v  a 2  s .  c om*/
    layout.makeColumnsEqualWidth = true;
    shell.setLayout(layout);

    // Create the big button in the upper left
    GridData data = new GridData(GridData.FILL_BOTH);
    data.widthHint = 200;
    Button one = new Button(shell, SWT.PUSH);
    one.setText("one");
    one.setLayoutData(data);

    // Create a composite to hold the three buttons in the upper right
    Composite composite = new Composite(shell, SWT.NONE);
    data = new GridData(GridData.FILL_BOTH);
    data.horizontalSpan = 2;
    composite.setLayoutData(data);
    layout = new GridLayout();
    layout.numColumns = 1;
    layout.marginHeight = 15;
    composite.setLayout(layout);

    // Create button "two"
    data = new GridData(GridData.FILL_BOTH);
    Button two = new Button(composite, SWT.PUSH);
    two.setText("two");
    two.setLayoutData(data);

    // Create button "three"
    data = new GridData(GridData.HORIZONTAL_ALIGN_CENTER);
    Button three = new Button(composite, SWT.PUSH);
    three.setText("three");
    three.setLayoutData(data);

    // Create button "four"
    data = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
    Button four = new Button(composite, SWT.PUSH);
    four.setText("four");
    four.setLayoutData(data);

    // Create the long button across the bottom
    data = new GridData();
    data.horizontalAlignment = GridData.FILL;
    data.grabExcessHorizontalSpace = true;
    data.horizontalSpan = 3;
    data.heightHint = 150;
    Button five = new Button(shell, SWT.PUSH);
    five.setText("five");
    five.setLayoutData(data);

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

From source file:ScrollWidgetViewFocusIn.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new GridLayout());
    Button b1 = new Button(shell, SWT.PUSH);
    b1.setText("top");
    b1.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
    final ScrolledComposite sc = new ScrolledComposite(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    sc.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    Composite c = new Composite(sc, SWT.NONE);
    c.setLayout(new GridLayout(10, true));
    for (int i = 0; i < 300; i++) {
        Button b = new Button(c, SWT.PUSH);
        b.setText("Button " + i);
    }/*from   ww w  .j av  a2 s. c  o m*/
    Button b2 = new Button(shell, SWT.PUSH);
    b2.setText("bottom");
    b2.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));

    sc.setContent(c);
    sc.setExpandHorizontal(true);
    sc.setExpandVertical(true);
    sc.setMinSize(c.computeSize(SWT.DEFAULT, SWT.DEFAULT));

    Listener listener = new Listener() {
        public void handleEvent(Event e) {
            Control child = (Control) e.widget;
            Rectangle bounds = child.getBounds();
            Rectangle area = sc.getClientArea();
            Point origin = sc.getOrigin();
            if (origin.x > bounds.x)
                origin.x = Math.max(0, bounds.x);
            if (origin.y > bounds.y)
                origin.y = Math.max(0, bounds.y);
            if (origin.x + area.width < bounds.x + bounds.width)
                origin.x = Math.max(0, bounds.x + bounds.width - area.width);
            if (origin.y + area.height < bounds.y + bounds.height)
                origin.y = Math.max(0, bounds.y + bounds.height - area.height);
            sc.setOrigin(origin);
        }
    };
    Control[] controls = c.getChildren();
    for (int i = 0; i < controls.length; i++) {
        controls[i].addListener(SWT.Activate, listener);
    }
    shell.setSize(300, 500);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}