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

void createAvailableTypes(Composite parent) {
    final List list = new List(parent, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    GridData data = new GridData(GridData.FILL_BOTH);
    data.heightHint = 100;/*from  w w w  . j av a 2s . com*/
    list.setLayoutData(data);
    Button b = new Button(parent, SWT.PUSH);
    b.setText("Get Available Types");
    b.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            list.removeAll();
            String[] names = clipboard.getAvailableTypeNames();
            for (int i = 0; i < names.length; i++) {
                list.add(names[i]);
            }
        }
    });
}

From source file:org.mwc.debrief.dis.views.DisListenerView.java

@Override
public void createPartControl(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    GridData gd = new GridData(SWT.FILL, SWT.FILL, true, false);
    composite.setLayoutData(gd);/*www.  j av  a2  s .  co m*/
    GridLayout layout = new GridLayout(1, false);
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    composite.setLayout(layout);

    Composite buttonComposite = new Composite(composite, SWT.NONE);
    gd = new GridData(SWT.FILL, SWT.FILL, false, false);
    gd.widthHint = 300;
    buttonComposite.setLayoutData(gd);
    layout = new GridLayout(4, false);
    layout.marginWidth = 5;
    layout.marginHeight = 5;
    buttonComposite.setLayout(layout);

    connectButton = createButton(buttonComposite, "Connect", 2);
    connectButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            // FIXME connect
        }

    });
    disconnectButton = createButton(buttonComposite, "Disconnect", 2);
    disconnectButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            // FIXME disconnect
        }

    });

    final Link link = new Link(buttonComposite, SWT.NONE);
    gd = new GridData(SWT.END, SWT.FILL, false, false);
    gd.horizontalSpan = 4;
    link.setLayoutData(gd);
    link.setText("<a href=\"id\">Server Prefs</a>");
    link.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            PreferenceDialog dialog = PreferencesUtil.createPreferenceDialogOn(link.getShell(), DisPrefs.ID,
                    null, null);
            dialog.open();
        }
    });
    link.setToolTipText("Dis Preferences");

    stopButton = createButton(buttonComposite, "Stop");
    stopButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            // FIXME stop
        }

    });

    pauseButton = createButton(buttonComposite, "Pause");
    pauseButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            // FIXME pause
        }

    });

    resumeButton = createButton(buttonComposite, "Resume");
    resumeButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            // FIXME resume
        }

    });

    playButton = createButton(buttonComposite, "Play");
    playButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            // FIXME play
        }

    });

    stopButton.setEnabled(false);
    pauseButton.setEnabled(false);
    resumeButton.setEnabled(false);
    disconnectButton.setEnabled(false);

    Label label = new Label(buttonComposite, SWT.NONE);
    gd = new GridData(SWT.FILL, SWT.FILL, false, false);
    label.setLayoutData(gd);
    label.setText("Path to input file:");

    Text text = new Text(buttonComposite, SWT.SINGLE | SWT.BORDER);
    gd = new GridData(SWT.FILL, SWT.FILL, false, false);
    gd.horizontalSpan = 2;
    gd.widthHint = 150;
    text.setLayoutData(gd);

    final Button browseButton = new Button(buttonComposite, SWT.PUSH);
    gd = new GridData(SWT.FILL, SWT.FILL, false, false);
    browseButton.setLayoutData(gd);
    browseButton.setText("Browse...");
    browseButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            FileDialog dialog = new FileDialog(getSite().getShell(), SWT.SINGLE);
            String value = pathText.getText();
            if (value.trim().length() == 0) {
                value = Platform.getLocation().toOSString();
            }
            dialog.setFilterPath(value);

            String result = dialog.open();
            if (result == null || result.trim().length() == 0) {
                return;
            }
            pathText.setText(result);

        }

    });

    Composite chartWrapperComposite = new Composite(composite, SWT.BORDER);
    gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    chartWrapperComposite.setLayoutData(gd);
    layout = new GridLayout(1, false);
    chartWrapperComposite.setLayout(layout);

    chartComposite = new ChartComposite(chartWrapperComposite, SWT.NONE, null, 400, 600, 300, 200, 1800, 1800,
            true, true, true, true, true, true) {
        @Override
        public void mouseUp(MouseEvent event) {
            super.mouseUp(event);
            JFreeChart c = getChart();
            if (c != null) {
                c.setNotify(true); // force redraw
            }
        }
    };

    Composite checkboxComposite = new Composite(composite, SWT.NONE);
    gd = new GridData(SWT.FILL, SWT.FILL, true, false);
    checkboxComposite.setLayoutData(gd);
    layout = new GridLayout(2, false);
    layout.marginWidth = 5;
    layout.marginHeight = 5;
    checkboxComposite.setLayout(layout);

    newPlotButton = new Button(checkboxComposite, SWT.CHECK);
    gd = new GridData(SWT.FILL, SWT.FILL, true, false);
    newPlotButton.setLayoutData(gd);
    newPlotButton.setText("New plot per replication");
    newPlotButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            // FIXME new plot ...
        }

    });
    liveUpdatesButton = new Button(checkboxComposite, SWT.CHECK);
    gd = new GridData(SWT.FILL, SWT.FILL, true, false);
    liveUpdatesButton.setLayoutData(gd);
    liveUpdatesButton.setText("Live updates");
    liveUpdatesButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            // FIXME Live updates.
        }

    });
    liveUpdatesButton.setSelection(true);

}

From source file:PersonEditor.java

/**
 * Creates the main window's contents/* w  w  w . j a va  2s. c o m*/
 * 
 * @param parent
 *            the main window
 * @return Control
 */
protected Control createContents(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new GridLayout(1, false));

    // Add a button to create the new person
    Button newPerson = new Button(composite, SWT.PUSH);
    newPerson.setText("Create New Person");

    // Add the TableViewer
    final TableViewer tv = new TableViewer(composite, SWT.FULL_SELECTION);
    tv.setContentProvider(new PersonContentProvider());
    tv.setLabelProvider(new PersonLabelProvider());
    tv.setInput(people);

    // Set up the table
    Table table = tv.getTable();
    table.setLayoutData(new GridData(GridData.FILL_BOTH));

    new TableColumn(table, SWT.CENTER).setText(NAME);
    new TableColumn(table, SWT.CENTER).setText(MALE);
    new TableColumn(table, SWT.CENTER).setText(AGE);
    new TableColumn(table, SWT.CENTER).setText(SHIRT_COLOR);

    for (int i = 0, n = table.getColumnCount(); i < n; i++) {
        table.getColumn(i).pack();
    }

    table.setHeaderVisible(true);
    table.setLinesVisible(true);

    // Add a new person when the user clicks button
    newPerson.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            Person p = new Person();
            p.setName("Name");
            p.setMale(true);
            p.setAgeRange(Integer.valueOf("0"));
            p.setShirtColor(new RGB(255, 0, 0));
            people.add(p);
            tv.refresh();
        }
    });

    // Create the cell editors
    CellEditor[] editors = new CellEditor[4];
    editors[0] = new TextCellEditor(table);
    editors[1] = new CheckboxCellEditor(table);
    editors[2] = new ComboBoxCellEditor(table, AgeRange.INSTANCES, SWT.READ_ONLY);
    editors[3] = new ColorCellEditor(table);

    // Set the editors, cell modifier, and column properties
    tv.setColumnProperties(PROPS);
    tv.setCellModifier(new PersonCellModifier(tv));
    tv.setCellEditors(editors);

    return composite;
}

From source file:ClipboardExample.java

void createHTMLTransfer(Composite copyParent, Composite pasteParent) {
    // HTML Transfer
    Label l = new Label(copyParent, SWT.NONE);
    l.setText("HTMLTransfer:"); //$NON-NLS-1$
    copyHtmlText = new Text(copyParent, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    copyHtmlText.setText("<b>Hello World</b>");
    GridData data = new GridData(GridData.FILL_HORIZONTAL);
    data.heightHint = data.widthHint = SIZE;
    copyHtmlText.setLayoutData(data);//from w w w .ja v  a  2 s. c  om
    Button b = new Button(copyParent, SWT.PUSH);
    b.setText("Copy");
    b.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            String data = copyHtmlText.getText();
            if (data.length() > 0) {
                status.setText("");
                clipboard.setContents(new Object[] { data }, new Transfer[] { HTMLTransfer.getInstance() });
            } else {
                status.setText("nothing to copy");
            }
        }
    });

    l = new Label(pasteParent, SWT.NONE);
    l.setText("HTMLTransfer:"); //$NON-NLS-1$
    pasteHtmlText = new Text(pasteParent, SWT.READ_ONLY | SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.heightHint = data.widthHint = SIZE;
    pasteHtmlText.setLayoutData(data);
    b = new Button(pasteParent, SWT.PUSH);
    b.setText("Paste");
    b.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            String data = (String) clipboard.getContents(HTMLTransfer.getInstance());
            if (data != null && data.length() > 0) {
                status.setText("");
                pasteHtmlText.setText("start paste>" + data + "<end paste");
            } else {
                status.setText("nothing to paste");
            }
        }
    });
}

From source file:ClipboardExample.java

void createTextTransfer(Composite copyParent, Composite pasteParent) {

    // TextTransfer
    Label l = new Label(copyParent, SWT.NONE);
    l.setText("TextTransfer:"); //$NON-NLS-1$
    copyText = new Text(copyParent, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    copyText.setText("some\nplain\ntext");
    GridData data = new GridData(GridData.FILL_HORIZONTAL);
    data.heightHint = data.widthHint = SIZE;
    copyText.setLayoutData(data);/*from w w  w  . jav  a2 s  .c om*/
    Button b = new Button(copyParent, SWT.PUSH);
    b.setText("Copy");
    b.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            String data = copyText.getText();
            if (data.length() > 0) {
                status.setText("");
                clipboard.setContents(new Object[] { data }, new Transfer[] { TextTransfer.getInstance() });
            } else {
                status.setText("nothing to copy");
            }
        }
    });

    l = new Label(pasteParent, SWT.NONE);
    l.setText("TextTransfer:"); //$NON-NLS-1$
    pasteText = new Text(pasteParent, SWT.READ_ONLY | SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.heightHint = data.widthHint = SIZE;
    pasteText.setLayoutData(data);
    b = new Button(pasteParent, SWT.PUSH);
    b.setText("Paste");
    b.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            String data = (String) clipboard.getContents(TextTransfer.getInstance());
            if (data != null && data.length() > 0) {
                status.setText("");
                pasteText.setText("begin paste>" + data + "<end paste");
            } else {
                status.setText("nothing to paste");
            }
        }
    });
}

From source file:ClipboardExample.java

void createRTFTransfer(Composite copyParent, Composite pasteParent) {
    // RTF Transfer
    Label l = new Label(copyParent, SWT.NONE);
    l.setText("RTFTransfer:"); //$NON-NLS-1$
    copyRtfText = new Text(copyParent, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    copyRtfText.setText("some\nrtf\ntext");
    GridData data = new GridData(GridData.FILL_HORIZONTAL);
    data.heightHint = data.widthHint = SIZE;
    copyRtfText.setLayoutData(data);/*from ww w .j a  v a 2s.  c om*/
    Button b = new Button(copyParent, SWT.PUSH);
    b.setText("Copy");
    b.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            String data = copyRtfText.getText();
            if (data.length() > 0) {
                status.setText("");
                data = "{\\rtf1{\\colortbl;\\red255\\green0\\blue0;}\\uc1\\b\\i " + data + "}";
                clipboard.setContents(new Object[] { data }, new Transfer[] { RTFTransfer.getInstance() });
            } else {
                status.setText("nothing to copy");
            }
        }
    });

    l = new Label(pasteParent, SWT.NONE);
    l.setText("RTFTransfer:"); //$NON-NLS-1$
    pasteRtfText = new Text(pasteParent, SWT.READ_ONLY | SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.heightHint = data.widthHint = SIZE;
    pasteRtfText.setLayoutData(data);
    b = new Button(pasteParent, SWT.PUSH);
    b.setText("Paste");
    b.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            String data = (String) clipboard.getContents(RTFTransfer.getInstance());
            if (data != null && data.length() > 0) {
                status.setText("");
                pasteRtfText.setText("start paste>" + data + "<end paste");
            } else {
                status.setText("nothing to paste");
            }
        }
    });
}

From source file:org.eclipse.swt.examples.clipboard.ClipboardExample.java

void createAvailableTypes(Composite parent) {
    final List list = new List(parent, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    GridData data = new GridData(GridData.FILL_BOTH);
    data.heightHint = VSIZE;//from   w w w .j a v a2 s  .c  o m
    list.setLayoutData(data);
    Button b = new Button(parent, SWT.PUSH);
    b.setText("Get Available Types");
    b.addSelectionListener(widgetSelectedAdapter(e -> {
        list.removeAll();
        String[] names = clipboard.getAvailableTypeNames();
        for (String name : names) {
            list.add(name);
        }
    }));
}

From source file:ClipboardExample.java

void createControlTransfer(Composite parent) {
    Label l = new Label(parent, SWT.NONE);
    l.setText("Text:");
    Button b = new Button(parent, SWT.PUSH);
    b.setText("Cut");
    b.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            text.cut();/*w w  w .j  a v a2 s.  co m*/
        }
    });
    b = new Button(parent, SWT.PUSH);
    b.setText("Copy");
    b.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            text.copy();
        }
    });
    b = new Button(parent, SWT.PUSH);
    b.setText("Paste");
    b.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            text.paste();
        }
    });
    text = new Text(parent, SWT.BORDER | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
    GridData data = new GridData(GridData.FILL_HORIZONTAL);
    data.heightHint = data.widthHint = SIZE;
    text.setLayoutData(data);

    l = new Label(parent, SWT.NONE);
    l.setText("Combo:");
    b = new Button(parent, SWT.PUSH);
    b.setText("Cut");
    b.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            combo.cut();
        }
    });
    b = new Button(parent, SWT.PUSH);
    b.setText("Copy");
    b.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            combo.copy();
        }
    });
    b = new Button(parent, SWT.PUSH);
    b.setText("Paste");
    b.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            combo.paste();
        }
    });
    combo = new Combo(parent, SWT.NONE);
    combo.setItems(new String[] { "Item 1", "Item 2", "Item 3", "A longer Item" });

    l = new Label(parent, SWT.NONE);
    l.setText("StyledText:");
    l = new Label(parent, SWT.NONE);
    l.setVisible(false);
    b = new Button(parent, SWT.PUSH);
    b.setText("Copy");
    b.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            styledText.copy();
        }
    });
    b = new Button(parent, SWT.PUSH);
    b.setText("Paste");
    b.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            styledText.paste();
        }
    });
    styledText = new StyledText(parent, SWT.BORDER | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.heightHint = data.widthHint = SIZE;
    styledText.setLayoutData(data);
}

From source file:ClipboardExample.java

void createFileTransfer(Composite copyParent, Composite pasteParent) {
    // File Transfer
    Label l = new Label(copyParent, SWT.NONE);
    l.setText("FileTransfer:"); //$NON-NLS-1$

    Composite c = new Composite(copyParent, SWT.NONE);
    c.setLayout(new GridLayout(2, false));
    GridData data = new GridData(GridData.FILL_HORIZONTAL);
    c.setLayoutData(data);/*from www  .  j  av  a  2s  .c  o  m*/

    copyFileTable = new Table(c, SWT.MULTI | SWT.BORDER);
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.heightHint = data.widthHint = SIZE;
    data.horizontalSpan = 2;
    copyFileTable.setLayoutData(data);

    Button b = new Button(c, SWT.PUSH);
    b.setText("Select file(s)");
    b.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            FileDialog dialog = new FileDialog(shell, SWT.OPEN | SWT.MULTI);
            String result = dialog.open();
            if (result != null && result.length() > 0) {
                // copyFileTable.removeAll();
                String separator = System.getProperty("file.separator");
                String path = dialog.getFilterPath();
                String[] names = dialog.getFileNames();
                for (int i = 0; i < names.length; i++) {
                    TableItem item = new TableItem(copyFileTable, SWT.NONE);
                    item.setText(path + separator + names[i]);
                }
            }
        }
    });
    b = new Button(c, SWT.PUSH);
    b.setText("Select directory");
    b.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            DirectoryDialog dialog = new DirectoryDialog(shell, SWT.OPEN);
            String result = dialog.open();
            if (result != null && result.length() > 0) {
                // copyFileTable.removeAll();
                TableItem item = new TableItem(copyFileTable, SWT.NONE);
                item.setText(result);
            }
        }
    });

    b = new Button(copyParent, SWT.PUSH);
    b.setText("Copy");
    b.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            TableItem[] items = copyFileTable.getItems();
            if (items.length > 0) {
                status.setText("");
                String[] data = new String[items.length];
                for (int i = 0; i < data.length; i++) {
                    data[i] = items[i].getText();
                }
                clipboard.setContents(new Object[] { data }, new Transfer[] { FileTransfer.getInstance() });
            } else {
                status.setText("nothing to copy");
            }
        }
    });

    l = new Label(pasteParent, SWT.NONE);
    l.setText("FileTransfer:"); //$NON-NLS-1$
    pasteFileTable = new Table(pasteParent, SWT.MULTI | SWT.BORDER);
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.heightHint = data.widthHint = SIZE;
    pasteFileTable.setLayoutData(data);
    b = new Button(pasteParent, SWT.PUSH);
    b.setText("Paste");
    b.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            String[] data = (String[]) clipboard.getContents(FileTransfer.getInstance());
            if (data != null && data.length > 0) {
                status.setText("");
                pasteFileTable.removeAll();
                for (int i = 0; i < data.length; i++) {
                    TableItem item = new TableItem(pasteFileTable, SWT.NONE);
                    item.setText(data[i]);
                }
            } else {
                status.setText("nothing to paste");
            }
        }
    });
}

From source file:ProgressBarDialog.java

protected void createContents() {
    setText("ProgressBar Dialog");
    setSize(218, 98);/*from   w ww.  j  a va2s  .c o  m*/
    setLayout(new FillLayout());

    final Button openProgressbarDialogButton = new Button(this, SWT.NONE);
    openProgressbarDialogButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            DemoProgressBar dpb = new DemoProgressBar(PBDialogDemo.this);
            dpb.initGuage();
            dpb.open();
        }
    });
    openProgressbarDialogButton.setText("Open ProgressBar Dialog");

}