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

public void open() {
    Shell parent = getParent();//from   w w w .  j a v  a2  s  .  c om
    final Shell dialog = new Shell(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
    dialog.setSize(200, 100);
    dialog.setText("About");
    final Label l = new Label(dialog, SWT.NONE);
    l.setText("An SWT Text Editor");
    l.setBounds(43, 20, 100, 20);
    Button b = new Button(dialog, SWT.PUSH | SWT.BORDER);
    b.setText("OK");
    b.setBounds(80, 45, 40, 25);
    b.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            dialog.dispose();
        }
    });
    dialog.open();
    Display display = parent.getDisplay();
    while (!dialog.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
}

From source file:msi.gama.hpc.gui.perspective.chart.HeadlessChart.java

private void createDataset() {
    lstvarname_flag = new ArrayList<String>();
    lsttimestep = new ArrayList<Integer>();
    lstchkbox = new ArrayList<Button>();
    readDataset();/*w w w.j  a v  a  2 s . co  m*/
    ArrayList<Result> listres = sim.result;
    int n = 0;
    series = new ArrayList<XYSeries>();
    for (int i = 0; i < listres.size(); i++) {
        String varname = listres.get(i).getName();
        if (lstvarname_flag.contains(varname)) {
            int idx = lstvarname_flag.indexOf(varname);
            lsttimestep.set(idx, lsttimestep.get(idx) + 1);
            series.get(idx).add(lsttimestep.get(idx), listres.get(i).getValue());
        } else {
            lstvarname_flag.add(varname);
            Button b1 = new Button(comp.getParent(), SWT.CHECK);
            b1.setText("Show " + varname);
            b1.setSelection(true);
            b1.addSelectionListener(new SelectionListener() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    // TODO Auto-generated method stub
                    showChart();
                }

                @Override
                public void widgetDefaultSelected(SelectionEvent e) {
                    // TODO Auto-generated method stub

                }

            });
            lstchkbox.add(b1);
            lsttimestep.add(new Integer(0));
            XYSeries ss = new XYSeries(varname);
            series.add(ss);
        }
        // System.out.println(" " + listres.get(i).getName()+" " + listres.get(i).getValue());
    }

}

From source file:MainClass.java

protected Control createContents(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new GridLayout(1, false));
    Button newPerson = new Button(composite, SWT.PUSH);
    newPerson.setText("Create New Person");

    final TableViewer tv = new TableViewer(composite, SWT.FULL_SELECTION);
    tv.setContentProvider(new PersonContentProvider());
    tv.setLabelProvider(new StudentLabelProvider());
    tv.setInput(studentList);//  w  w w . j a  va2 s . c o m
    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);

    newPerson.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            Student p = new Student();
            p.setName("Name");
            p.setMale(true);
            p.setAgeRange(Integer.valueOf("0"));
            p.setShirtColor(new RGB(255, 0, 0));
            studentList.add(p);
            tv.refresh();
        }
    });

    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);

    tv.setColumnProperties(PROPS);
    tv.setCellModifier(new StudentCellModifier(tv));
    tv.setCellEditors(editors);

    return composite;
}

From source file:CoolBarExamples.java

public CoolBarExamples() {
    shell.setLayout(new GridLayout());

    final CoolBar coolBar = new CoolBar(shell, SWT.NONE);

    coolBar.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    // cool item with a text field.
    CoolItem textItem = new CoolItem(coolBar, SWT.NONE);

    Text text = new Text(coolBar, SWT.BORDER | SWT.DROP_DOWN);
    text.setText("TEXT");
    text.pack();//ww  w  .j  ava2 s.c  om

    Point size = text.getSize();
    textItem.setControl(text);
    textItem.setSize(textItem.computeSize(size.x, size.y));

    // cool item with a label.
    CoolItem labelItem = new CoolItem(coolBar, SWT.NONE);

    Label label = new Label(coolBar, SWT.NONE);
    label.setText("LABEL");
    label.pack();

    size = label.getSize();
    labelItem.setControl(label);
    labelItem.setSize(textItem.computeSize(size.x, size.y));

    // cool item with a button.
    CoolItem buttonItem = new CoolItem(coolBar, SWT.NONE | SWT.DROP_DOWN);

    Composite composite = new Composite(coolBar, SWT.NONE);
    composite.setLayout(new GridLayout(2, true));

    Button button1 = new Button(composite, SWT.PUSH);
    button1.setText("Button 1");
    button1.pack();

    Button button2 = new Button(composite, SWT.PUSH);
    button2.setText("Button 2");
    button2.pack();

    composite.pack();

    size = composite.getSize();
    buttonItem.setControl(composite);
    buttonItem.setSize(buttonItem.computeSize(size.x, size.y));

    //      // Test cool item adding method.
    //      Label label2 = new Label(coolBar, SWT.NONE);
    //      label2.setText("label2");
    //      addControlToCoolBar(label2, SWT.DROP_DOWN, coolBar);

    try {
        setState(coolBar, new File("coolbar.state"));
    } catch (IOException e1) {
        e1.printStackTrace();
    }

    shell.addListener(SWT.Close, new Listener() {
        public void handleEvent(Event event) {
            try {
                saveState(coolBar, new File("coolbar.state"));
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    });

    shell.setSize(300, 120);
    // 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:ShowPrefs.java

/**
 * Add buttons/*from  w  ww.  j  ava  2s . c o  m*/
 * 
 * @param parent the parent composite
 */
protected void contributeButtons(Composite parent) {
    // Add a select all button
    Button selectAll = new Button(parent, SWT.PUSH);
    selectAll.setText("Select All");
    selectAll.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            checkOne.setSelection(true);
            checkTwo.setSelection(true);
            checkThree.setSelection(true);
        }
    });

    // Add a select all button
    Button clearAll = new Button(parent, SWT.PUSH);
    clearAll.setText("Clear All");
    clearAll.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            checkOne.setSelection(false);
            checkTwo.setSelection(false);
            checkThree.setSelection(false);
        }
    });

    // Add two columns to the parent's layout
    ((GridLayout) parent.getLayout()).numColumns += 2;
}

From source file:SWT2D.java

private void run() {
    // Create top level shell
    final Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("Java 2D Example");
    // GridLayout for canvas and button
    shell.setLayout(new GridLayout());
    // Create container for AWT canvas
    final Composite canvasComp = new Composite(shell, SWT.EMBEDDED);
    // Set preferred size
    GridData data = new GridData();
    data.widthHint = 600;//from ww  w.j  a v  a  2 s  . c o  m
    data.heightHint = 500;
    canvasComp.setLayoutData(data);
    // Create AWT Frame for Canvas
    java.awt.Frame canvasFrame = SWT_AWT.new_Frame(canvasComp);
    // Create Canvas and add it to the Frame
    final java.awt.Canvas canvas = new java.awt.Canvas();
    canvasFrame.add(canvas);
    // Get graphical context and cast to Java2D
    final java.awt.Graphics2D g2d = (java.awt.Graphics2D) canvas.getGraphics();
    // Enable antialiasing
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    // Remember initial transform
    final java.awt.geom.AffineTransform origTransform = g2d.getTransform();
    // Create Clear button and position it
    Button clearButton = new Button(shell, SWT.PUSH);
    clearButton.setText("Clear");
    data = new GridData();
    data.horizontalAlignment = GridData.CENTER;
    clearButton.setLayoutData(data);
    // Event processing for Clear button
    clearButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            // Delete word list and redraw canvas
            wordList.clear();
            canvasComp.redraw();
        }
    });
    // Process canvas mouse clicks
    canvas.addMouseListener(new java.awt.event.MouseListener() {
        public void mouseClicked(java.awt.event.MouseEvent e) {
        }

        public void mouseEntered(java.awt.event.MouseEvent e) {
        }

        public void mouseExited(java.awt.event.MouseEvent e) {
        }

        public void mousePressed(java.awt.event.MouseEvent e) {
            // Manage pop-up editor
            display.syncExec(new Runnable() {
                public void run() {
                    if (eShell == null) {
                        // Create new Shell: non-modal!
                        eShell = new Shell(shell, SWT.NO_TRIM | SWT.MODELESS);
                        eShell.setLayout(new FillLayout());
                        // Text input field
                        eText = new Text(eShell, SWT.BORDER);
                        eText.setText("Text rotation in the SWT?");
                        eShell.pack();
                        // Set position (Display coordinates)
                        java.awt.Rectangle bounds = canvas.getBounds();
                        org.eclipse.swt.graphics.Point pos = canvasComp.toDisplay(bounds.width / 2,
                                bounds.height / 2);
                        Point size = eShell.getSize();
                        eShell.setBounds(pos.x, pos.y, size.x, size.y);
                        // Open Shell
                        eShell.open();
                    } else if (!eShell.isVisible()) {
                        // Editor versteckt, sichtbar machen
                        eShell.setVisible(true);
                    } else {
                        // Editor is visible - get text
                        String t = eText.getText();
                        // set editor invisible
                        eShell.setVisible(false);
                        // Add text to list and redraw canvas
                        wordList.add(t);
                        canvasComp.redraw();
                    }
                }
            });
        }

        public void mouseReleased(java.awt.event.MouseEvent e) {
        }
    });
    // Redraw the canvas
    canvasComp.addPaintListener(new PaintListener() {
        public void paintControl(PaintEvent e) {
            // Pass the redraw task to AWT event queue
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    // Compute canvas center
                    java.awt.Rectangle bounds = canvas.getBounds();
                    int originX = bounds.width / 2;
                    int originY = bounds.height / 2;
                    // Reset canvas
                    g2d.setTransform(origTransform);
                    g2d.setColor(java.awt.Color.WHITE);
                    g2d.fillRect(0, 0, bounds.width, bounds.height);
                    // Set font
                    g2d.setFont(new java.awt.Font("Myriad", java.awt.Font.PLAIN, 32));
                    double angle = 0d;
                    // Prepare star shape
                    double increment = Math.toRadians(30);
                    Iterator iter = wordList.iterator();
                    while (iter.hasNext()) {
                        // Determine text colors in RGB color cycle
                        float red = (float) (0.5 + 0.5 * Math.sin(angle));
                        float green = (float) (0.5 + 0.5 * Math.sin(angle + Math.toRadians(120)));
                        float blue = (float) (0.5 + 0.5 * Math.sin(angle + Math.toRadians(240)));
                        g2d.setColor(new java.awt.Color(red, green, blue));
                        // Redraw text
                        String text = (String) iter.next();
                        g2d.drawString(text, originX + 50, originY);
                        // Rotate for next text output
                        g2d.rotate(increment, originX, originY);
                        angle += increment;
                    }
                }
            });
        }
    });
    // Finish shell and open it
    shell.pack();
    shell.open();
    // SWT event processing
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:ShowPrograms.java

/**
 * Creates the main window's contents/*from w w  w . j  av  a  2  s.c o m*/
 * 
 * @param shell the main window
 */
private void createContents(Shell shell) {
    shell.setLayout(new GridLayout(2, false));

    // Create the label and combo for the extensions
    new Label(shell, SWT.NONE).setText("Extension:");
    Combo extensionsCombo = new Combo(shell, SWT.BORDER | SWT.READ_ONLY);
    extensionsCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    // Create the label and the
    new Label(shell, SWT.NONE).setText("Program:");
    final Label programName = new Label(shell, SWT.NONE);
    programName.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    // Fill the combo with the extensions on the system
    String[] extensions = Program.getExtensions();
    for (int i = 0, n = extensions.length; i < n; i++) {
        extensionsCombo.add(extensions[i]);
    }

    // Add a handler to get the selected extension, look up the associated
    // program, and display the program's name
    extensionsCombo.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            Combo combo = (Combo) event.widget;

            // Get the program for the extension
            Program program = Program.findProgram(combo.getText());

            // Display the program's name
            programName.setText(program == null ? "(None)" : program.getName());
        }
    });

    // Create a list box to show all the programs on the system
    List allPrograms = new List(shell, SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    GridData data = new GridData(GridData.FILL_BOTH);
    data.horizontalSpan = 2;
    allPrograms.setLayoutData(data);

    // Put all the known programs into the list box
    Program[] programs = Program.getPrograms();
    for (int i = 0, n = programs.length; i < n; i++) {
        String name = programs[i].getName();
        allPrograms.add(name);
        allPrograms.setData(name, programs[i]);
    }

    // Add a field for a data file
    new Label(shell, SWT.NONE).setText("Data File:");
    final Text dataFile = new Text(shell, SWT.BORDER);
    dataFile.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    // Double-clicking a program in the list launches the program
    allPrograms.addMouseListener(new MouseAdapter() {
        public void mouseDoubleClick(MouseEvent event) {
            List list = (List) event.widget;
            if (list.getSelectionCount() > 0) {
                String programName = list.getSelection()[0];
                Program program = (Program) list.getData(programName);
                program.execute(dataFile.getText());
            }
        }
    });

    // Let them use launch instead of execute
    Button launch = new Button(shell, SWT.PUSH);
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.horizontalSpan = 2;
    launch.setLayoutData(data);
    launch.setText("Use Program.launch() instead of Program.execute()");
    launch.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            // Use launch
            Program.launch(dataFile.getText());
        }
    });
}

From source file:FoodList.java

/**
 * Creates the main window's contents/* w w  w  .j  ava  2  s .  com*/
 * 
 * @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 checkbox to toggle filter
    Button filterHealthy = new Button(composite, SWT.CHECK);
    filterHealthy.setText("&Show only healthy");

    final ListViewer lv = new ListViewer(composite);
    lv.setContentProvider(new FoodContentProvider());
    lv.setLabelProvider(new FoodLabelProvider());
    lv.setInput(new GroceryList());

    // When user checks the checkbox, toggle the filter
    filterHealthy.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            if (((Button) event.widget).getSelection())
                lv.addFilter(filter);
            else
                lv.removeFilter(filter);
        }
    });

    parent.pack();
    return composite;
}

From source file:org.eclipse.swt.examples.addressbook.SearchDialog.java

/**
 * Class constructor that sets the parent shell and the table widget that
 * the dialog will search.//from   w w  w.j ava  2  s .  c o  m
 *
 * @param parent   Shell
 *         The shell that is the parent of the dialog.
 */
public SearchDialog(Shell parent) {
    shell = new Shell(parent, SWT.CLOSE | SWT.BORDER | SWT.TITLE);
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    shell.setLayout(layout);
    shell.setText(resAddressBook.getString("Search_dialog_title"));
    shell.addShellListener(ShellListener.shellClosedAdapter(e -> {
        // don't dispose of the shell, just hide it for later use
        e.doit = false;
        shell.setVisible(false);
    }));

    Label label = new Label(shell, SWT.LEFT);
    label.setText(resAddressBook.getString("Dialog_find_what"));
    searchText = new Text(shell, SWT.BORDER);
    GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.widthHint = 200;
    searchText.setLayoutData(gridData);
    searchText.addModifyListener(e -> {
        boolean enableFind = (searchText.getCharCount() != 0);
        findButton.setEnabled(enableFind);
    });

    searchAreaLabel = new Label(shell, SWT.LEFT);
    searchArea = new Combo(shell, SWT.DROP_DOWN | SWT.READ_ONLY);
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.widthHint = 200;
    searchArea.setLayoutData(gridData);

    matchCase = new Button(shell, SWT.CHECK);
    matchCase.setText(resAddressBook.getString("Dialog_match_case"));
    gridData = new GridData();
    gridData.horizontalSpan = 2;
    matchCase.setLayoutData(gridData);

    matchWord = new Button(shell, SWT.CHECK);
    matchWord.setText(resAddressBook.getString("Dialog_match_word"));
    gridData = new GridData();
    gridData.horizontalSpan = 2;
    matchWord.setLayoutData(gridData);

    Group direction = new Group(shell, SWT.NONE);
    gridData = new GridData();
    gridData.horizontalSpan = 2;
    direction.setLayoutData(gridData);
    direction.setLayout(new FillLayout());
    direction.setText(resAddressBook.getString("Dialog_direction"));

    Button up = new Button(direction, SWT.RADIO);
    up.setText(resAddressBook.getString("Dialog_dir_up"));
    up.setSelection(false);

    down = new Button(direction, SWT.RADIO);
    down.setText(resAddressBook.getString("Dialog_dir_down"));
    down.setSelection(true);

    Composite composite = new Composite(shell, SWT.NONE);
    gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    gridData.horizontalSpan = 2;
    composite.setLayoutData(gridData);
    layout = new GridLayout();
    layout.numColumns = 2;
    layout.makeColumnsEqualWidth = true;
    composite.setLayout(layout);

    findButton = new Button(composite, SWT.PUSH);
    findButton.setText(resAddressBook.getString("Dialog_find"));
    findButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));
    findButton.setEnabled(false);
    findButton.addSelectionListener(widgetSelectedAdapter(e -> {
        if (!findHandler.find()) {
            MessageBox box = new MessageBox(shell, SWT.ICON_INFORMATION | SWT.OK | SWT.PRIMARY_MODAL);
            box.setText(shell.getText());
            box.setMessage(resAddressBook.getString("Cannot_find") + "\"" + searchText.getText() + "\"");
            box.open();
        }
    }));

    Button cancelButton = new Button(composite, SWT.PUSH);
    cancelButton.setText(resAddressBook.getString("Cancel"));
    cancelButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
    cancelButton.addSelectionListener(widgetSelectedAdapter(e -> shell.setVisible(false)));
    shell.pack();
}

From source file:Ch12FileBrowserComposite.java

public Ch12FileBrowserComposite(Composite parent) {
    super(parent, SWT.NONE);

    RowLayout layout = new RowLayout(SWT.HORIZONTAL);
    setLayout(layout);/*www .j  a  v a2s  . co m*/

    Button copyButton = new Button(this, SWT.PUSH);
    copyButton.setText("Copy");
    copyButton.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            Clipboard clipboard = new Clipboard(getDisplay());

            FileTransfer transfer = FileTransfer.getInstance();
            clipboard.setContents(new Object[] { browser.getSelectedFiles() }, new Transfer[] { transfer });
            clipboard.dispose();
        }

        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });

    Button pasteButton = new Button(this, SWT.PUSH);
    pasteButton.setText("Paste");
    pasteButton.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            Clipboard clipboard = new Clipboard(getDisplay());
            FileTransfer transfer = FileTransfer.getInstance();

            Object data = clipboard.getContents(transfer);
            if (data != null) {
                browser.copyFiles((String[]) data);
            }
            clipboard.dispose();
        }

        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });

    browser = new FileBrowser(this);
    new FileBrowser(this);
}