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:GridLayoutSizeHint.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 a  v a  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");
    GridData gridData = new GridData();
    gridData.widthHint = 200;
    gridData.heightHint = 200;
    list.setLayoutData(gridData);

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

    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:org.eclipse.swt.snippets.Snippet344.java

public static void main(String[] args) {
    Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("Snippet 344");
    shell.setLayout(new GridLayout(1, false));

    Button button = new Button(shell, SWT.PUSH);
    button.setText("Click me");
    button.addSelectionListener(widgetSelectedAdapter(e -> {
        Shell shell2 = new Shell(SWT.TOOL | SWT.RESIZE | SWT.CLOSE | SWT.MAX);
        shell2.setLayout(new GridLayout(1, false));
        shell2.setText("Palette");
        Label l = new Label(shell2, SWT.LEFT);
        l.setText("This is a SWT.TOOL Shell");
        Point origin = shell.getLocation();
        origin.x += 100;/*  ww w.  j  ava  2s. c  o m*/
        origin.y += 100;
        shell2.pack();
        shell2.open();
    }));

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

From source file:Snippet63.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.pack();//w  ww .ja  v a 2  s.  co m
    shell.open();
    final boolean[] result = new boolean[1];
    final Shell dialog = new Shell(shell, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
    dialog.setLayout(new RowLayout());
    final Button ok = new Button(dialog, SWT.PUSH);
    ok.setText("Ok");
    Button cancel = new Button(dialog, SWT.PUSH);
    cancel.setText("Cancel");
    Listener listener = new Listener() {
        public void handleEvent(Event event) {
            result[0] = event.widget == ok;
            dialog.close();
        }
    };
    ok.addListener(SWT.Selection, listener);
    cancel.addListener(SWT.Selection, listener);
    dialog.pack();
    dialog.open();
    System.out.println("Prompt ...");
    while (!dialog.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    System.out.println("Result: " + result[0]);
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

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

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

    // this button is always 400 x 400. Scrollbars appear if the window is resized to be
    // too small to show part of the button
    ScrolledComposite c1 = new ScrolledComposite(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    Button b1 = new Button(c1, SWT.PUSH);
    b1.setText("fixed size button");
    b1.setSize(400, 400);//from   www . ja  v a 2  s .  co m
    c1.setContent(b1);

    // this button has a minimum size of 400 x 400. If the window is resized to be big
    // enough to show more than 400 x 400, the button will grow in size. If the window
    // is made too small to show 400 x 400, scrollbars will appear.
    ScrolledComposite c2 = new ScrolledComposite(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    Button b2 = new Button(c2, SWT.PUSH);
    b2.setText("expanding button");
    c2.setContent(b2);
    c2.setExpandHorizontal(true);
    c2.setExpandVertical(true);
    c2.setMinSize(400, 400);

    shell.setSize(600, 300);
    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;//ww w  . j a  va 2s  .  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");
    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:MainClass.java

public static void main(String[] a) {
    final Display d = new Display();
    final Shell s = new Shell(d);

    s.setSize(300, 300);//  w  w w  .j av a2s . c o  m

    s.setText("A ColorDialog Example");
    s.setLayout(new FillLayout(SWT.VERTICAL));
    final Text t = new Text(s, SWT.BORDER | SWT.MULTI);
    final Button b = new Button(s, SWT.PUSH | SWT.BORDER);
    b.setText("Change Color");
    b.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            ColorDialog cd = new ColorDialog(s);
            cd.setText("ColorDialog Demo");
            cd.setRGB(new RGB(255, 255, 255));
            RGB newColor = cd.open();
            if (newColor == null) {
                return;
            }
            t.setBackground(new Color(d, newColor));
        }
    });
    s.open();

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

}

From source file:Snippet71.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.pack();//from  w w  w  . j  a  va  2s.co  m
    shell.open();
    Shell dialog = new Shell(shell, SWT.DIALOG_TRIM);
    Label label = new Label(dialog, SWT.NONE);
    label.setText("Exit the application?");
    Button okButton = new Button(dialog, SWT.PUSH);
    okButton.setText("&OK");
    Button cancelButton = new Button(dialog, SWT.PUSH);
    cancelButton.setText("&Cancel");

    FormLayout form = new FormLayout();
    form.marginWidth = form.marginHeight = 8;
    dialog.setLayout(form);
    FormData okData = new FormData();
    okData.top = new FormAttachment(label, 8);
    okButton.setLayoutData(okData);
    FormData cancelData = new FormData();
    cancelData.left = new FormAttachment(okButton, 8);
    cancelData.top = new FormAttachment(okButton, 0, SWT.TOP);
    cancelButton.setLayoutData(cancelData);

    dialog.setDefaultButton(okButton);
    dialog.pack();
    dialog.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 w  w  w  . j av a2  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.Snippet253.java

public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("Snippet 253");
    FillLayout layout = new FillLayout(SWT.VERTICAL);
    shell.setLayout(layout);// ww  w.java2 s . com
    final Table table = new Table(shell, SWT.NONE);
    for (int i = 0; i < 32; i++) {
        TableItem item = new TableItem(table, SWT.NONE);
        item.setText("Item " + (i + 1) + " is quite long");
    }
    final Button button = new Button(shell, SWT.PUSH);
    button.setText("Visible Items []");
    button.addListener(SWT.Selection, e -> {
        Rectangle rect = table.getClientArea();
        int itemHeight = table.getItemHeight();
        int headerHeight = table.getHeaderHeight();
        int visibleCount = (rect.height - headerHeight + itemHeight - 1) / itemHeight;
        button.setText("Visible Items [" + visibleCount + "]");
    });
    shell.setSize(200, 250);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:ComboSelectedIndex.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Show Message Box");
    shell.setLayout(new GridLayout(2, false));
    new Label(shell, SWT.NONE).setText("Icon:");
    final Combo icons = new Combo(shell, SWT.DROP_DOWN | SWT.READ_ONLY);
    icons.add("A");
    icons.add("B");
    icons.add("C");
    icons.select(0);/*from   w  w w  .j  av  a  2  s. co m*/

    new Label(shell, SWT.NONE).setText("Buttons:");
    final Combo buttons = new Combo(shell, SWT.DROP_DOWN | SWT.READ_ONLY);
    buttons.add("1");
    buttons.add("2");
    buttons.select(0);

    new Label(shell, SWT.NONE).setText("Return:");
    final Label returnVal = new Label(shell, SWT.NONE);
    returnVal.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    Button button = new Button(shell, SWT.PUSH);
    button.setText("Show Message");
    button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {

            returnVal.setText("");

            returnVal.setText(icons.getSelectionIndex() + " " + buttons.getSelectionIndex());
        }
    });
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    display.dispose();
}