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:RowLayoutAlignColumn.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;//from   w w w . j a  va2s.  co m
    layout.fill = true;
    layout.justify = false;
    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();
}

From source file:CanvasControlAdd.java

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

    Canvas canvas = new Canvas(shell, SWT.NONE);

    Button button = new Button(canvas, SWT.PUSH);
    button.setBounds(10, 10, 300, 40);//  w  w w  . ja  v  a2 s  . c om
    button.setText("You can place widgets on a canvas");

    canvas.addPaintListener(new PaintListener() {
        public void paintControl(PaintEvent e) {
            Rectangle rect = ((Canvas) e.widget).getBounds();
            e.gc.setForeground(e.display.getSystemColor(SWT.COLOR_RED));
            e.gc.drawFocus(5, 5, rect.width - 10, rect.height - 10);
            e.gc.drawText("You can draw text directly on a canvas", 60, 60);
        }
    });

    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
    final Shell shell = new Shell(display);

    shell.setLayout(new GridLayout(2, false));

    final Label fontLabel = new Label(shell, SWT.NONE);
    fontLabel.setText("The selected font");

    Button button = new Button(shell, SWT.PUSH);
    button.setText("Font...");
    button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            // Create the color-change dialog
            FontDialog dlg = new FontDialog(shell);
            Font font = null;//from   w w w. ja va  2  s  .  com
            Color color = null;

            if (font != null)
                dlg.setFontList(fontLabel.getFont().getFontData());
            if (color != null)
                dlg.setRGB(color.getRGB());

            if (dlg.open() != null) {
                if (font != null)
                    font.dispose();
                if (color != null)
                    color.dispose();

                font = new Font(shell.getDisplay(), dlg.getFontList());
                fontLabel.setFont(font);

                color = new Color(shell.getDisplay(), dlg.getRGB());
                fontLabel.setForeground(color);

                shell.pack();
            }
        }
    });

    shell.open();

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

From source file:SyncExecExample.java

public static void main(String[] args) {

    final Display display = new Display();
    Shell shell = new Shell(display);

    final Runnable print = new Runnable() {
        public void run() {
            System.out.println("Print from thread: \t" + Thread.currentThread().getName());
        }//  w ww.  j a  v  a2 s  . c o  m
    };

    final Thread applicationThread = new Thread("applicationThread") {
        public void run() {
            System.out.println("Hello from thread: \t" + Thread.currentThread().getName());
            display.syncExec(print);
            System.out.println("Bye from thread: \t" + Thread.currentThread().getName());
        }
    };

    shell.setText("syncExec Example");
    shell.setSize(300, 100);

    Button button = new Button(shell, SWT.CENTER);
    button.setText("Click to start");
    button.setBounds(shell.getClientArea());
    button.addSelectionListener(new SelectionListener() {
        public void widgetDefaultSelected(SelectionEvent e) {
        }

        public void widgetSelected(SelectionEvent e) {
            applicationThread.start();
        }
    });

    shell.open();

    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {// If no more entries in event queue
            display.sleep();
        }
    }

    display.dispose();

}

From source file:ControlEditorWithDialog.java

public static void main(String[] args) {

    final Shell shell = new Shell(display);
    shell.setText("Control Editor Two");

    final Composite composite = new Composite(shell, SWT.NONE);
    composite.setBackground(color);//  w w w  . ja  v  a  2 s. c  o m
    composite.setBounds(0, 0, 300, 100);

    ControlEditor editor = new ControlEditor(composite);

    // Create the control associated with the editor
    Button button = new Button(composite, SWT.PUSH);
    button.setText("Change Color...");
    button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            ColorDialog dialog = new ColorDialog(shell);
            if (color != null)
                dialog.setRGB(color.getRGB());
            RGB rgb = dialog.open();
            if (rgb != null) {
                if (color != null)
                    color.dispose();
                color = new Color(shell.getDisplay(), rgb);
                composite.setBackground(color);
            }
        }
    });
    // Place the editor along the bottom of the parent composite
    editor.grabHorizontal = true;
    editor.verticalAlignment = SWT.BOTTOM;
    Point size = button.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    editor.minimumHeight = size.y;
    editor.setEditor(button);

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

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

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 358");
    shell.setLayout(new GridLayout());
    final Tree tree = new Tree(shell, SWT.NONE);
    tree.setLayoutData(new GridData(200, 200));
    for (int i = 0; i < 9; i++) {
        TreeItem item = new TreeItem(tree, SWT.NONE);
        item.setText("root-level item " + i);
        for (int j = 0; j < 9; j++) {
            new TreeItem(item, SWT.NONE).setText("item " + i + "-" + j);
        }//from  www.j  a  v a  2  s  .c o m
    }

    Button button = new Button(shell, SWT.PUSH);
    button.setText("Print item visibilities");
    button.addListener(SWT.Selection, event -> {
        Rectangle treeBounds = new Rectangle(0, 0, 0, 0);
        Point treeSize = tree.getSize();
        treeBounds.width = treeSize.x;
        treeBounds.height = treeSize.y;
        TreeItem[] rootItems = tree.getItems();
        for (int i = 0; i < rootItems.length; i++) {
            TreeItem rootItem = rootItems[i];
            System.out.println(rootItem.getText() + " is at least partially visible? "
                    + treeBounds.intersects(rootItem.getBounds()));
            TreeItem[] childItems = rootItem.getItems();
            for (int j = 0; j < childItems.length; j++) {
                TreeItem childItem = childItems[j];
                System.out.println(childItem.getText() + " is at least partially visible? "
                        + treeBounds.intersects(childItem.getBounds()));
            }
        }
    });

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

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

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

    Image i = new Image(display, Snippet364.class.getResourceAsStream("eclipse.png"));
    Button b = new Button(shell, SWT.PUSH | SWT.LEFT_TO_RIGHT);
    b.setText("Button LEFT_TO_RIGHT...");
    b.setImage(i);/* w ww  . j av a  2  s . c om*/

    Button b2 = new Button(shell, SWT.PUSH | SWT.RIGHT_TO_LEFT);
    b2.setText("Button RIGHT_TO_LEFT...");
    b2.setImage(i);

    new Label(shell, SWT.NONE).setText("with FLIP_TEXT_DIRECTION:");

    Button b3 = new Button(shell, SWT.PUSH | SWT.LEFT_TO_RIGHT | SWT.FLIP_TEXT_DIRECTION);
    b3.setText("Button LEFT_TO_RIGHT...");
    b3.setImage(i);

    Button b4 = new Button(shell, SWT.PUSH | SWT.RIGHT_TO_LEFT | SWT.FLIP_TEXT_DIRECTION);
    b4.setText("Button RIGHT_TO_LEFT...");
    b4.setImage(i);

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

From source file:ScreenshotCaptureGC.java

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

    Button button = new Button(shell, SWT.PUSH);
    button.setText("Capture");
    button.pack();/*  w  ww. jav  a2  s  .c  om*/
    button.setLocation(10, 140);
    button.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event event) {
            GC gc = new GC(display);
            final Image image = new Image(display, 400, 400);
            gc.copyArea(image, 0, 0);
            gc.dispose();

            Shell popup = new Shell(shell);
            popup.setText("Image");
            popup.addListener(SWT.Close, new Listener() {
                public void handleEvent(Event e) {
                    image.dispose();
                }
            });

            Canvas canvas = new Canvas(popup, SWT.NONE);
            canvas.setBounds(10, 10, 400 + 10, 400 + 10);
            canvas.addPaintListener(new PaintListener() {
                public void paintControl(PaintEvent e) {
                    e.gc.drawImage(image, 0, 0);
                }
            });
            popup.pack();
            popup.open();
        }
    });
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

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

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 176");
    RowLayout layout = new RowLayout(SWT.HORIZONTAL);
    layout.wrap = true;/*from w  w  w .  j a v  a  2 s. co  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();
}

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

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 177");
    RowLayout layout = new RowLayout(SWT.VERTICAL);
    layout.wrap = true;//w w  w. j a v a 2s .  c  o  m
    layout.fill = true;
    layout.justify = false;
    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();
}