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:ButtonSelection.java

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

    for (int i = 0; i < 20; i++) {
        Button button = new Button(shell, SWT.TOGGLE);
        button.setText("B" + i);
    }//  w w w  .  j ava2s .  c o m
    Control[] children = shell.getChildren();
    for (int i = 0; i < children.length; i++) {
        Control child = children[i];
        ((Button) child).setSelection(true);
    }

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

From source file:CoolBarComboButton.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    CoolBar bar = new CoolBar(shell, SWT.BORDER);

    CoolItem item = new CoolItem(bar, SWT.NONE);
    Button button = new Button(bar, SWT.PUSH);
    button.setText("Button ");
    Point size = button.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    item.setPreferredSize(item.computeSize(size.x, size.y));
    item.setControl(button);//from ww w. j av a2  s  . c o  m

    item = new CoolItem(bar, SWT.NONE);
    Combo combo = new Combo(bar, SWT.NONE);
    size = combo.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    item.setPreferredSize(item.computeSize(size.x, size.y));
    item.setControl(combo);

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

From source file:TabItemSelection.java

public static void main(String[] args) {
    Display display = new Display();
    final Shell shell = new Shell(display);
    final TabFolder tabFolder = new TabFolder(shell, SWT.BORDER);
    for (int i = 0; i < 6; i++) {
        TabItem item = new TabItem(tabFolder, SWT.NONE);
        item.setText("TabItem " + i);
        Button button = new Button(tabFolder, SWT.PUSH);
        button.setText("Page " + i);
        item.setControl(button);//from w w w.j  a  v  a 2 s . co  m
    }
    tabFolder.setSelection(2);

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

From source file:TabListFocusTransfer.java

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

    Button b1 = new Button(shell, SWT.PUSH);
    b1.setText("1");
    Button b2 = new Button(shell, SWT.RADIO);
    b2.setText("2");
    Button b3 = new Button(shell, SWT.RADIO);
    b3.setText("3");
    Button b4 = new Button(shell, SWT.RADIO);
    b4.setText("4");
    Button b5 = new Button(shell, SWT.PUSH);
    b5.setText("5");

    Control[] tabList1 = new Control[] { b2, b1, b3, b5, b4 };
    shell.setTabList(tabList1);//ww  w .  j  av  a2  s .  c o m

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

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

From source file:FormLayoutLeftRight.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);/*from  w  w w.  j  a v a  2s  . co m*/

    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:FormLayoutAttachFourSidesControl.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");

    FormData formData = new FormData();
    formData.left = new FormAttachment(50);
    formData.right = new FormAttachment(100);
    formData.top = new FormAttachment(50);
    formData.bottom = new FormAttachment(100);

    button1.setLayoutData(formData);/*from  www . j  a va  2s. co  m*/

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

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

From source file:TabItemWithToolTipImage.java

public static void main(String[] args) {
    Display display = new Display();
    final Shell shell = new Shell(display);
    final TabFolder tabFolder = new TabFolder(shell, SWT.BORDER);
    for (int i = 0; i < 6; i++) {
        TabItem item = new TabItem(tabFolder, SWT.NONE);
        item.setText("TabItem " + i);
        item.setToolTipText("This is my tab" + i);
        item.setImage(new Image(display, "yourFile.gif"));
        Button button = new Button(tabFolder, SWT.PUSH);
        button.setText("Page " + i);
        item.setControl(button);//  w ww .j a v a 2  s . c o  m
    }
    tabFolder.pack();
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:UntypedEventListener.java

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

    Button button = new Button(shell, SWT.NONE);
    button.setText("Click and check the console");
    button.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event e) {

            System.out.println(e.button);

            switch (e.type) {
            case SWT.Selection:
                System.out.println("Button pressed");
                break;
            }/* w  w  w.  j av a 2  s . co m*/
        }
    });

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

From source file:ScollCompositeControl.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    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 w w w.  jav  a 2s  .c om
    c1.setContent(b1);

    shell.setSize(600, 300);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:FormLayoutControlOffsetAttachment.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");

    Point size = button1.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    int offset = size.x / 2;

    FormData formData = new FormData();
    formData.left = new FormAttachment(50, -1 * offset);

    button1.setLayoutData(formData);//from  www .j ava2s.  c  o  m

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

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