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:FormLayoutCenterAnotherControl.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("button222222222222222222222");

    FormData formData = new FormData();
    formData.left = new FormAttachment(button1);
    button2.setLayoutData(formData);//  www .  j a  va2  s .  c om

    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.CENTER);
    button3.setLayoutData(formData);

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

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

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

public static void main(String[] args) {
    final Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 347");
    shell.setLayout(new GridLayout(1, false));
    Menu appMenuBar = display.getMenuBar();
    if (appMenuBar == null) {
        appMenuBar = new Menu(shell, SWT.BAR);
        shell.setMenuBar(appMenuBar);/*from   w w w. j  a v a 2 s.  com*/
    }
    MenuItem file = new MenuItem(appMenuBar, SWT.CASCADE);
    file.setText("File");
    Menu dropdown = new Menu(appMenuBar);
    file.setMenu(dropdown);
    MenuItem exit = new MenuItem(dropdown, SWT.PUSH);
    exit.setText("Exit");
    exit.addSelectionListener(widgetSelectedAdapter(e -> display.dispose()));
    Button b = new Button(shell, SWT.PUSH);
    b.setText("Test");
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:SWTButtonExampleDemo.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setSize(300, 200);/*from  ww  w  . ja  v a2 s . c  o m*/
    shell.setText("Button Example");
    shell.setLayout(new RowLayout());

    final Button button = new Button(shell, SWT.PUSH);
    button.setText("Click Me");

    final Text text = new Text(shell, SWT.SHADOW_IN);

    button.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent event) {
            text.setText("No worries!");
        }

        public void widgetDefaultSelected(SelectionEvent event) {
            text.setText("No worries!");
        }
    });
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

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

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 188");
    shell.setLayout(new GridLayout());
    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  a  v  a2 s  .co  m
    sc.setContent(c);
    sc.setExpandHorizontal(true);
    sc.setExpandVertical(true);
    sc.setMinSize(c.computeSize(SWT.DEFAULT, SWT.DEFAULT));
    sc.setShowFocusedControl(true);

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

From source file:MainClass.java

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

    GridData data = new GridData(GridData.FILL_BOTH);
    Button one = new Button(shell, SWT.PUSH);
    one.setText("one");
    one.setLayoutData(data);

    data = new GridData(GridData.FILL_BOTH);
    Button two = new Button(shell, SWT.PUSH);
    two.setText("two");
    two.setLayoutData(data);

    data = new GridData(GridData.FILL_BOTH);
    Button three = new Button(shell, SWT.PUSH);
    three.setText("three");
    three.setLayoutData(data);

    data = new GridData(GridData.FILL_BOTH);
    Button four = new Button(shell, SWT.PUSH);
    four.setText("four");
    four.setLayoutData(data);

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

From source file:MainClass.java

public static void main(String[] a) {
    Display display = new Display();

    // Create the main window
    Shell mainShell = new Shell(display);
    final Shell childShell = new Shell(mainShell);
    childShell.addDisposeListener(new DisposeListener() {
        public void widgetDisposed(DisposeEvent event) {
            System.out.println("Gotcha");
        }/* w w  w .  j av  a 2  s  .  c o m*/
    });
    childShell.setLayout(new FillLayout());
    childShell.setText("little brother");

    Button button = new Button(childShell, SWT.PUSH);
    button.setText("Close Me!");
    button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            childShell.close();
        }
    });

    childShell.open();

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

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

public static void main(String[] args) {
    Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("Snippet 76");
    final TabFolder tabFolder = new TabFolder(shell, SWT.BORDER);
    Rectangle clientArea = shell.getClientArea();
    tabFolder.setLocation(clientArea.x, clientArea.y);
    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);//w  w w  . jav a 2s. c o  m
    }
    tabFolder.pack();
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:Snippet5.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);/* ww  w.  j  av a 2s.c o  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.setMinWidth(400);
    c2.setMinHeight(400);

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

From source file:GridLayout2x2.java

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

    GridLayout layout = new GridLayout();
    layout.numColumns = 2;//  w  ww .j a  v a2 s  . c o m
    layout.makeColumnsEqualWidth = true;
    shell.setLayout(layout);

    GridData data = new GridData(GridData.FILL_BOTH);
    Button one = new Button(shell, SWT.PUSH);
    one.setText("one");
    one.setLayoutData(data);

    data = new GridData(GridData.FILL_BOTH);
    Button two = new Button(shell, SWT.PUSH);
    two.setText("two");
    two.setLayoutData(data);

    data = new GridData(GridData.FILL_BOTH);
    Button three = new Button(shell, SWT.PUSH);
    three.setText("three");
    three.setLayoutData(data);

    data = new GridData(GridData.FILL_BOTH);
    Button four = new Button(shell, SWT.PUSH);
    four.setText("four");
    four.setLayoutData(data);

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

From source file:ButtonImageAdd.java

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

    shell.setLayout(new FillLayout());

    Image image = new Image(display, "yourFile.gif");

    Button button = new Button(shell, SWT.PUSH);

    button.setImage(image);/*from ww  w  .  j a v  a  2s  .co m*/
    button.setText("button");

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