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

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

Introduction

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

Prototype

public void setText(String text) 

Source Link

Document

Sets the receiver's text.

Usage

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

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 127");
    shell.setLayout(new RowLayout());
    Button button1 = new Button(shell, SWT.PUSH);
    button1.setText("Can't Traverse");
    button1.addTraverseListener(e -> {
        switch (e.detail) {
        case SWT.TRAVERSE_TAB_NEXT:
        case SWT.TRAVERSE_TAB_PREVIOUS: {
            e.doit = false;/*from  ww  w  .  j av a 2s .  c  om*/
        }
        }
    });
    Button button2 = new Button(shell, SWT.PUSH);
    button2.setText("Can Traverse");
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

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

public static void main(String[] args) {
    Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("Snippet 4");
    Button b = new Button(shell, SWT.PUSH);
    b.setText("Open Dialog ...");
    b.pack();//from   w  ww .ja  v  a 2 s .  c om
    Rectangle clientArea = shell.getClientArea();
    b.setLocation(clientArea.x + 10, clientArea.y + 10);
    b.addSelectionListener(widgetSelectedAdapter(e -> {
        Shell dialog = new Shell(shell, SWT.DIALOG_TRIM);
        dialog.addListener(SWT.Traverse, t -> {
            if (t.detail == SWT.TRAVERSE_ESCAPE) {
                t.doit = false;
            }
        });
        dialog.open();
    }));
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:FormLayoutAttachEachOther.java

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);//  www . j av  a 2  s  .c o  m

    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();
}

From source file:GridLayoutMargin.java

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

    GridLayout gridLayout = new GridLayout();
    gridLayout.marginHeight = 20;/*  w  w w.  j a va 2s  .  co  m*/
    gridLayout.marginWidth = 30;

    shell.setLayout(gridLayout);

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

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

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

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

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

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

From source file:GridLayoutSpacing.java

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

    GridLayout gridLayout = new GridLayout();
    gridLayout.horizontalSpacing = 20;/* w w  w  .j  av  a2 s .com*/
    gridLayout.verticalSpacing = 30;

    shell.setLayout(gridLayout);

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

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

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

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

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

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

From source file:RowLayoutMargin.java

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

    RowLayout rowLayout = new RowLayout();

    rowLayout.marginLeft = 20;//from www .  j  a v  a2s .c  o m
    rowLayout.marginRight = 20;
    rowLayout.marginTop = 20;
    rowLayout.marginBottom = 20;

    shell.setLayout(rowLayout);

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

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

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

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

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

From source file:GridLayoutMakeColumnWidth.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  .j  a  va 2 s.  c  om
    gridLayout.makeColumnsEqualWidth = true;

    shell.setLayout(gridLayout);

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

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

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

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

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

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

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

public static void main(java.lang.String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 293");
    shell.setLayout(new GridLayout());

    Button b1 = new Button(shell, SWT.CHECK);
    b1.setText("State 1");
    b1.setSelection(true);//from  w  ww  .  j  a  v a 2s .co  m

    Button b2 = new Button(shell, SWT.CHECK);
    b2.setText("State 2");
    b2.setSelection(false);

    Button b3 = new Button(shell, SWT.CHECK);
    b3.setText("State 3");
    b3.setSelection(true);
    b3.setGrayed(true);

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

From source file:LayoutTerm.java

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

    System.out.println("Bounds: " + shell.getBounds());
    System.out.println("Client area: " + shell.getClientArea());

    shell.setBackground(display.getSystemColor(SWT.COLOR_WHITE));

    RowLayout rowLayout = new RowLayout();

    shell.setLayout(rowLayout);/* w w  w .j  a  v  a 2s  .c o m*/

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

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

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

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

    System.out.println("button1: " + button1.getBounds());
    System.out.println("button2: " + button2.getBounds());

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

From source file:FormLayoutAnotherControl.java

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

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

    FormData formData = new FormData();
    formData.left = new FormAttachment(button1);
    button2.setLayoutData(formData);/*w w  w . j  a  va 2s .com*/

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

    formData = new FormData();
    formData.top = new FormAttachment(button2, 10);
    formData.left = new FormAttachment(button2, 0, SWT.LEFT);
    button3.setLayoutData(formData);

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

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