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.Snippet175.java

public static void main(String[] args) {

    Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("Snippet 175");
    shell.setLayout(new GridLayout(3, false));

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

    final Button bHidden = new Button(shell, SWT.PUSH);
    bHidden.setText("Button 1");
    GridData data = new GridData();
    data.exclude = true;/*w w w . j  a  va 2  s . c  om*/
    data.horizontalSpan = 2;
    data.horizontalAlignment = SWT.FILL;
    bHidden.setLayoutData(data);

    b = new Button(shell, SWT.PUSH);
    b.setText("Button 2");
    b = new Button(shell, SWT.PUSH);
    b.setText("Button 3");
    b = new Button(shell, SWT.PUSH);
    b.setText("Button 4");

    b = new Button(shell, SWT.CHECK);
    b.setText("hide");
    b.setSelection(true);
    b.addListener(SWT.Selection, e -> {
        Button b1 = (Button) e.widget;
        GridData data1 = (GridData) bHidden.getLayoutData();
        data1.exclude = b1.getSelection();
        bHidden.setVisible(!data1.exclude);
        shell.layout(false);
    });
    shell.setSize(400, 400);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

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

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 247");
    shell.setLayout(new RowLayout());
    Text text = new Text(shell, SWT.MULTI | SWT.BORDER);
    String modifier = SWT.MOD1 == SWT.CTRL ? "Ctrl" : "Command";
    text.setText("Hit " + modifier + "+Return\nto see\nthe default button\nrun");
    text.addTraverseListener(e -> {// w w w  . j  a v  a2  s  . c om
        switch (e.detail) {
        case SWT.TRAVERSE_RETURN:
            if ((e.stateMask & SWT.MOD1) != 0)
                e.doit = true;
        }
    });
    Button button = new Button(shell, SWT.PUSH);
    button.pack();
    button.setText("OK");
    button.addSelectionListener(widgetSelectedAdapter(e -> System.out.println("OK selected")));

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

From source file:CompositeCreateDisposeChildren.java

public static void main(String args[]) {
    Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setLayout(new GridLayout());
    Button button = new Button(shell, SWT.PUSH);
    button.setText("Push");
    pageComposite = new Composite(shell, SWT.NONE);
    pageComposite.setLayout(new GridLayout());
    pageComposite.setLayoutData(new GridData());

    button.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event event) {
            if ((pageComposite != null) && (!pageComposite.isDisposed())) {
                pageComposite.dispose();
            }//from  w  ww  .j ava 2  s . com
            pageComposite = new Composite(shell, SWT.NONE);
            pageComposite.setLayout(new GridLayout());
            pageComposite.setLayoutData(new GridData());
            if (pageNum++ % 2 == 0) {
                Table table = new Table(pageComposite, SWT.BORDER);
                table.setLayoutData(new GridData());
                for (int i = 0; i < 5; i++) {
                    new TableItem(table, SWT.NONE).setText("table item " + i);
                }
            } else {
                new Button(pageComposite, SWT.RADIO).setText("radio");
            }
            shell.layout(true);
        }
    });

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

From source file:FormLayoutComposite.java

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

    Composite composite = new Composite(shell, SWT.NONE);

    GridLayout gridLayout = new GridLayout();
    gridLayout.marginHeight = 0;//w  ww .j  av  a  2 s .c  o m
    gridLayout.marginWidth = 0;
    composite.setLayout(gridLayout);
    Button two = new Button(composite, SWT.PUSH);
    two.setText("two");
    GridData gridData = new GridData(GridData.FILL_BOTH);
    two.setLayoutData(gridData);
    Button three = new Button(composite, SWT.PUSH);
    three.setText("three");
    gridData = new GridData(GridData.FILL_BOTH);
    three.setLayoutData(gridData);
    Button four = new Button(composite, SWT.PUSH);
    four.setText("four");
    gridData = new GridData(GridData.FILL_BOTH);
    four.setLayoutData(gridData);

    Button five = new Button(shell, SWT.PUSH);
    five.setText("five");
    FormData data = new FormData();
    data.top = new FormAttachment(two, 5);
    data.left = new FormAttachment(0, 5);
    data.bottom = new FormAttachment(100, -5);
    data.right = new FormAttachment(100, -5);
    five.setLayoutData(data);

    data = new FormData();
    data.top = new FormAttachment(0, 5);
    data.left = new FormAttachment(two, 5);
    data.bottom = new FormAttachment(50, -5);
    data.right = new FormAttachment(100, -5);
    composite.setLayoutData(data);

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

From source file:Snippet46.java

public static void main(String[] args) {
    Display display = new Display();
    final Shell shell = new Shell(display);
    final Composite composite = new Composite(shell, SWT.NONE);
    composite.setEnabled(false);//from  www  . j  av a2 s. c om
    composite.setLayout(new FillLayout());
    Button button = new Button(composite, SWT.PUSH);
    button.setText("Button");
    composite.pack();
    composite.setLocation(10, 10);
    final Point[] offset = new Point[1];
    Listener listener = new Listener() {
        public void handleEvent(Event event) {
            switch (event.type) {
            case SWT.MouseDown:
                Rectangle rect = composite.getBounds();
                if (rect.contains(event.x, event.y)) {
                    Point pt1 = composite.toDisplay(0, 0);
                    Point pt2 = shell.toDisplay(event.x, event.y);
                    offset[0] = new Point(pt2.x - pt1.x, pt2.y - pt1.y);
                }
                break;
            case SWT.MouseMove:
                if (offset[0] != null) {
                    Point pt = offset[0];
                    composite.setLocation(event.x - pt.x, event.y - pt.y);
                }
                break;
            case SWT.MouseUp:
                offset[0] = null;
                break;
            }
        }
    };
    shell.addListener(SWT.MouseDown, listener);
    shell.addListener(SWT.MouseUp, listener);
    shell.addListener(SWT.MouseMove, listener);
    shell.setSize(300, 300);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:GridLayoutWidgetExclude.java

public static void main(String[] args) {

    Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setLayout(new GridLayout(3, false));

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

    final Button bHidden = new Button(shell, SWT.PUSH);
    bHidden.setText("Button 1");
    GridData data = new GridData();
    data.exclude = true;//from www.j  av a2  s. c  o m
    data.horizontalSpan = 2;
    data.horizontalAlignment = SWT.FILL;
    bHidden.setLayoutData(data);

    b = new Button(shell, SWT.PUSH);
    b.setText("Button 2");
    b = new Button(shell, SWT.PUSH);
    b.setText("Button 3");
    b = new Button(shell, SWT.PUSH);
    b.setText("Button 4");

    b = new Button(shell, SWT.CHECK);
    b.setText("hide");
    b.setSelection(true);
    b.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event e) {
            Button b = (Button) e.widget;
            GridData data = (GridData) bHidden.getLayoutData();
            data.exclude = b.getSelection();
            bHidden.setVisible(!data.exclude);
            shell.layout(false);
        }
    });
    shell.setSize(400, 400);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:Snippet127.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    Button button1 = new Button(shell, SWT.PUSH);
    button1.setBounds(10, 10, 80, 30);/*w  w w  .  j  a v  a  2  s.  co  m*/
    button1.setText("no traverse");
    button1.addTraverseListener(new TraverseListener() {
        public void keyTraversed(TraverseEvent e) {
            switch (e.detail) {
            case SWT.TRAVERSE_TAB_NEXT:
            case SWT.TRAVERSE_TAB_PREVIOUS: {
                e.doit = false;
            }
            }
        }
    });
    Button button2 = new Button(shell, SWT.PUSH);
    button2.setBounds(100, 10, 80, 30);
    button2.setText("can traverse");
    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 a 2 s .c  o  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: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();/*from w  ww .j  a  v  a  2 s.  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:RowLayoutAlignWidgets.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    RowLayout layout = new RowLayout(SWT.HORIZONTAL);
    layout.wrap = true;/* ww w. jav a2s. c  o m*/
    layout.fill = false;
    layout.justify = true;
    shell.setLayout(layout);

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

    b.setText("Button 2");

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

    b = new Button(shell, SWT.PUSH);
    b.setText("Not shown");
    b.setVisible(false);
    RowData data = new RowData();
    data.exclude = true;
    b.setLayoutData(data);

    b = new Button(shell, SWT.PUSH);
    b.setText("Button 200 high");
    data = new RowData();
    data.height = 200;
    b.setLayoutData(data);

    b = new Button(shell, SWT.PUSH);
    b.setText("Button 200 wide");
    data = new RowData();
    data.width = 200;
    b.setLayoutData(data);

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