Example usage for org.eclipse.swt.widgets Button Button

List of usage examples for org.eclipse.swt.widgets Button Button

Introduction

In this page you can find the example usage for org.eclipse.swt.widgets Button Button.

Prototype


public Button(Composite parent, int style) 

Source Link

Document

Constructs a new instance of this class given its parent and a style value describing its behavior and appearance.

Usage

From source file:ShowProgress.java

/**
 * Creates the main window's contents/*w ww  . j  av a2  s. 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, true));

    // Create the indeterminate checkbox
    final Button indeterminate = new Button(composite, SWT.CHECK);
    indeterminate.setText("Indeterminate");

    // Create the ShowProgress button
    Button showProgress = new Button(composite, SWT.NONE);
    showProgress.setText("Show Progress");

    final Shell shell = parent.getShell();

    // Display the ProgressMonitorDialog
    showProgress.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            try {
                new ProgressMonitorDialog(shell).run(true, true,
                        new LongRunningOperation(indeterminate.getSelection()));
            } catch (InvocationTargetException e) {
                MessageDialog.openError(shell, "Error", e.getMessage());
            } catch (InterruptedException e) {
                MessageDialog.openInformation(shell, "Cancelled", e.getMessage());
            }
        }
    });

    parent.pack();
    return composite;
}

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

private static void makeAlignGroup() {
    Group alignGroup = new Group(shell, SWT.None);
    alignGroup.setLayout(new RowLayout());
    alignGroup.setText("Alignment group");

    final AtomicInteger prevDir = new AtomicInteger(0);
    final Button alignmentButton = new Button(alignGroup, SWT.ARROW | SWT.UP);
    alignmentButton.addListener(SWT.MouseDown, event -> {
        switch (prevDir.get()) {
        case 0://from   w w  w .java2s . c o m
            alignmentButton.setAlignment(SWT.RIGHT);
            prevDir.set(1);
            break;
        case 1:
            alignmentButton.setAlignment(SWT.DOWN);
            prevDir.set(2);
            break;
        case 2:
            alignmentButton.setAlignment(SWT.LEFT);
            prevDir.set(3);
            break;
        case 3:
            alignmentButton.setAlignment(SWT.UP);
            prevDir.set(0);
        default:
            break;
        }
    });
}

From source file:GetInput.java

/**
 * Creates the main window's contents//w ww .jav  a  2  s  .  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));

    // Create a label to display what the user typed in
    final Label label = new Label(composite, SWT.NONE);
    label.setText("This will display the user input from InputDialog");

    // Create the button to launch the error dialog
    Button show = new Button(composite, SWT.PUSH);
    show.setText("Get Input");
    show.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            InputDialog dlg = new InputDialog(Display.getCurrent().getActiveShell(), "", "Enter 5-8 characters",
                    label.getText(), new LengthValidator());
            if (dlg.open() == Window.OK) {
                // User clicked OK; update the label with the input
                label.setText(dlg.getValue());
            }
        }
    });

    parent.pack();
    return composite;
}

From source file:RoundRectangleExample.java

/**
 * Creates the main window's contents/*from w w  w.j a va  2s  . c  om*/
 * 
 * @param shell the main window
 */
private void createContents(Shell shell) {
    shell.setLayout(new FillLayout(SWT.VERTICAL));

    // Create the composite that holds the input fields
    Composite widgetComposite = new Composite(shell, SWT.NONE);
    widgetComposite.setLayout(new GridLayout(2, false));

    // Create the input fields
    new Label(widgetComposite, SWT.NONE).setText("Arc Width:");
    txtArcWidth = new Text(widgetComposite, SWT.BORDER);

    new Label(widgetComposite, SWT.NONE).setText("Arc Height");
    txtArcHeight = new Text(widgetComposite, SWT.BORDER);

    // Create the button that launches the redraw
    Button button = new Button(widgetComposite, SWT.PUSH);
    button.setText("Redraw");
    shell.setDefaultButton(button);

    // Create the canvas to draw the round rectangle on
    final Canvas drawingCanvas = new Canvas(shell, SWT.NONE);
    drawingCanvas.addPaintListener(new RoundRectangleExamplePaintListener());

    // Add a handler to redraw the round rectangle when pressed
    button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            drawingCanvas.redraw();
        }
    });
}

From source file:ShowError.java

/**
 * Creates the main window's contents/*from w  ww . java 2 s .  co  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));

    // Create a big text box to accept error text
    final Text text = new Text(composite, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL);
    text.setLayoutData(new GridData(GridData.FILL_BOTH));

    // Create the button to launch the error dialog
    Button show = new Button(composite, SWT.PUSH);
    show.setText("Show Error");
    show.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            // Create the required Status object
            Status status = new Status(IStatus.ERROR, "My Plug-in ID", 0, "Status Error Message", null);

            // Display the dialog
            ErrorDialog.openError(Display.getCurrent().getActiveShell(), "JFace Error", text.getText(), status);
        }
    });

    return composite;
}

From source file:SimpleFileBrowser.java

private void init() {
    shell.setText("File Browser");
    shell.setLayout(new GridLayout(1, true));

    Button button = new Button(shell, SWT.PUSH);
    button.setText("Browse ...");
    button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            DirectoryDialog dialog = new DirectoryDialog(shell, SWT.NULL);
            String path = dialog.open();
            if (path != null) {

                File file = new File(path);
                if (file.isFile())
                    displayFiles(new String[] { file.toString() });
                else
                    displayFiles(file.list());

            }/* w  w  w .ja v a  2  s  .co m*/
        }
    });

    GridData gd = new GridData(GridData.FILL_BOTH);

    table = new Table(shell, SWT.MULTI);
    table.setLayoutData(gd);

    // creates an image registry and adds icons to the image registry.
    imageRegistry = new ImageRegistry();

    ImageDescriptor defaultIcon = ImageDescriptor.createFromFile(null, "java2s.gif");
    imageRegistry.put("default", defaultIcon);

    ImageDescriptor jarIcon = ImageDescriptor.createFromFile(null, "img/jar.gif");
    imageRegistry.put("jar", jarIcon);
}

From source file:org.eclipse.swt.examples.controlexample.GroupTab.java

/**
 * Creates the "Other" group./*w w w.  j  ava 2  s  .  com*/
 */
@Override
void createOtherGroup() {
    super.createOtherGroup();

    /* Create display controls specific to this example */
    titleButton = new Button(otherGroup, SWT.CHECK);
    titleButton.setText(ControlExample.getResourceString("Title_Text"));

    /* Add the listeners */
    titleButton.addSelectionListener(widgetSelectedAdapter(event -> setTitleText()));
}

From source file:Look.java

/**
 * Creates the main window's contents/*from  w w  w.ja  v  a2 s  .c o  m*/
 * 
 * @param parent the main window
 */
public void createContents(Composite parent) {
    parent.setLayout(new GridLayout(1, false));

    // Pressing the "New Document" button will create a new ViewForm
    Button button = new Button(parent, SWT.PUSH);
    button.setText("New Document");

    // Create the composite that holds the ViewForms
    final Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayoutData(new GridData(GridData.FILL_BOTH));
    composite.setLayout(new FillLayout());

    // Add the event handler to create the ViewForms
    button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            createViewFormHelper(composite, "Document " + (++count));
            composite.layout();
        }
    });
}

From source file:SearchStyleText.java

public SearchStyleText() {
    shell.setLayout(new GridLayout(2, false));

    styledText = new StyledText(shell, SWT.MULTI | SWT.WRAP | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    GridData gridData = new GridData(GridData.FILL_BOTH);
    gridData.horizontalSpan = 2;/*from w w w. j  a va2  s .c om*/
    styledText.setLayoutData(gridData);

    keywordText = new Text(shell, SWT.SINGLE | SWT.BORDER);
    keywordText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    Font font = new Font(shell.getDisplay(), "Courier New", 12, SWT.NORMAL);
    styledText.setFont(font);

    button = new Button(shell, SWT.PUSH);
    button.setText("Search");
    button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            keyword = keywordText.getText();
            styledText.redraw();
        }
    });

    styledText.addLineStyleListener(new LineStyleListener() {
        public void lineGetStyle(LineStyleEvent event) {
            if (keyword == null || keyword.length() == 0) {
                event.styles = new StyleRange[0];
                return;
            }

            String line = event.lineText;
            int cursor = -1;

            LinkedList list = new LinkedList();
            while ((cursor = line.indexOf(keyword, cursor + 1)) >= 0) {
                list.add(getHighlightStyle(event.lineOffset + cursor, keyword.length()));
            }

            event.styles = (StyleRange[]) list.toArray(new StyleRange[list.size()]);
        }
    });

    keyword = "SW";

    styledText.setText("AWT, SWING \r\nSWT & JFACE");

    shell.pack();
    shell.open();
    //textUser.forceFocus();

    // 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:RegistryTest.java

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

    // Set up the registries
    CR = new ColorRegistry();
    CR.addListener(this);

    FR = new FontRegistry();
    FR.addListener(this);

    // Create the label
    label = new Label(composite, SWT.CENTER);
    label.setText("Hello from JFace");

    // Create the randomize button
    Button button = new Button(composite, SWT.PUSH);
    button.setText("Randomize");
    button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            CR.put(FOREGROUND, new RGB((int) (Math.random() * 255), (int) (Math.random() * 255),
                    (int) (Math.random() * 255)));
            CR.put(BACKGROUND, new RGB((int) (Math.random() * 255), (int) (Math.random() * 255),
                    (int) (Math.random() * 255)));
            FontData fontData = new FontData("Times New Roman", (int) (Math.random() * 72), SWT.BOLD);
            FR.put(FONT, new FontData[] { fontData });
        }
    });
    return composite;
}