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

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

Introduction

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

Prototype

public void setBounds(int x, int y, int width, int height) 

Source Link

Document

Sets the receiver's size and location to the rectangular area specified by the arguments.

Usage

From source file:MouseTrackExample.java

public MouseTrackExample() {
    d = new Display();
    s = new Shell(d);

    s.setSize(250, 200);/*from   ww  w  . jav a 2s.  co m*/

    s.setText("A MouseTrackListener Example");
    final Button b = new Button(s, SWT.PUSH);
    b.setText("Push Me");
    b.setBounds(20, 50, 55, 25);
    s.open();
    final Color oldColor = b.getBackground();

    b.addMouseTrackListener(new MouseTrackAdapter() {
        public void mouseEnter(MouseEvent e) {
            b.setBackground(new Color(d, 0, 153, 153));

        }

        public void mouseExit(MouseEvent e) {
            b.setBackground(oldColor);
        }
    });

    while (!s.isDisposed()) {
        if (!d.readAndDispatch())
            d.sleep();
    }
    d.dispose();
}

From source file:CompViewer.java

public Ch3_Group(Composite parent) {
    super(parent, SWT.NONE);
    Group group = new Group(this, SWT.SHADOW_ETCHED_IN);
    group.setText("Group Label");

    Label label = new Label(group, SWT.NONE);
    label.setText("Two buttons:");
    label.setLocation(20, 20);/*from w w  w.j a v a  2s .  c  o m*/
    label.pack();

    Button button1 = new Button(group, SWT.PUSH);
    button1.setText("Push button");
    button1.setLocation(20, 45);
    button1.pack();

    Button button2 = new Button(group, SWT.CHECK);
    button2.setText("Check button");
    button2.setBounds(20, 75, 90, 30);
    group.pack();
}

From source file:GroupShellExample2.java

GroupShellExample2() {
    d = new Display();
    s = new Shell(d);
    s.setSize(200, 200);/*from w w w  . ja v  a  2 s . c  om*/

    s.setText("A Group Example");
    final Group g = new Group(s, SWT.SHADOW_ETCHED_IN);
    g.setSize(110, 75);
    g.setText("Options Group");
    final Button b1;
    final Button b2;
    final Button b3;
    b1 = new Button(g, SWT.RADIO);
    b1.setBounds(10, 20, 75, 15);
    b1.setText("Option One");
    b2 = new Button(g, SWT.RADIO);
    b2.setBounds(10, 35, 75, 15);
    b2.setText("Option Two");
    b3 = new Button(g, SWT.RADIO);
    b3.setBounds(10, 50, 80, 15);
    b3.setText("Option Three");
    g.pack();
    g.setLocation(20, 20);
    s.open();
    while (!s.isDisposed()) {
        if (!d.readAndDispatch())
            d.sleep();
    }
    d.dispose();
}

From source file:SWTTextEditor.java

public void open() {
    Shell parent = getParent();//from  ww w .ja  v  a 2s .c  o m
    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:org.eclipse.swt.examples.controlexample.ShellTab.java

/**
 * Handle the Create button selection event.
 *
 * @param event org.eclipse.swt.events.SelectionEvent
 *///from   w  w  w .j  av a2  s.com
public void createButtonSelected(SelectionEvent event) {

    /*
     * Remember the example shells so they
     * can be disposed by the user.
     */
    if (shellCount >= shells.length) {
        Shell[] newShells = new Shell[shells.length + 4];
        System.arraycopy(shells, 0, newShells, 0, shells.length);
        shells = newShells;
    }

    /* Compute the shell style */
    int style = SWT.NONE;
    if (noTrimButton.getSelection())
        style |= SWT.NO_TRIM;
    if (noMoveButton.getSelection())
        style |= SWT.NO_MOVE;
    if (closeButton.getSelection())
        style |= SWT.CLOSE;
    if (titleButton.getSelection())
        style |= SWT.TITLE;
    if (minButton.getSelection())
        style |= SWT.MIN;
    if (maxButton.getSelection())
        style |= SWT.MAX;
    if (borderButton.getSelection())
        style |= SWT.BORDER;
    if (resizeButton.getSelection())
        style |= SWT.RESIZE;
    if (onTopButton.getSelection())
        style |= SWT.ON_TOP;
    if (toolButton.getSelection())
        style |= SWT.TOOL;
    if (sheetButton.getSelection())
        style |= SWT.SHEET;
    if (modelessButton.getSelection())
        style |= SWT.MODELESS;
    if (primaryModalButton.getSelection())
        style |= SWT.PRIMARY_MODAL;
    if (applicationModalButton.getSelection())
        style |= SWT.APPLICATION_MODAL;
    if (systemModalButton.getSelection())
        style |= SWT.SYSTEM_MODAL;

    /* Create the shell with or without a parent */
    if (noParentButton.getSelection()) {
        shells[shellCount] = new Shell(style);
    } else {
        shells[shellCount] = new Shell(shell, style);
    }
    final Shell currentShell = shells[shellCount];
    currentShell.setBackgroundMode(SWT.INHERIT_DEFAULT);
    final Button button = new Button(currentShell, SWT.CHECK);
    button.setBounds(20, 20, 120, 30);
    button.setText(ControlExample.getResourceString("FullScreen"));
    button.addSelectionListener(widgetSelectedAdapter(e -> currentShell.setFullScreen(button.getSelection())));
    Button close = new Button(currentShell, SWT.PUSH);
    close.setBounds(160, 20, 120, 30);
    close.setText(ControlExample.getResourceString("Close"));
    close.addListener(SWT.Selection, event1 -> {
        currentShell.dispose();
        shellCount--;
    });

    /* Set the size, title, and image, and open the shell */
    currentShell.setSize(300, 100);
    currentShell.setText(ControlExample.getResourceString("Title") + shellCount);
    if (imageButton.getSelection())
        currentShell.setImage(instance.images[ControlExample.ciTarget]);
    if (backgroundImageButton.getSelection())
        currentShell.setBackgroundImage(instance.images[ControlExample.ciBackground]);
    hookListeners(currentShell);
    currentShell.open();
    shellCount++;
}

From source file:CustomControlExample.java

/**
 * Handle the Create button selection event.
 * /*from ww  w.  j  av  a2 s  .c o m*/
 * @param event
 *            org.eclipse.swt.events.SelectionEvent
 */
public void createButtonSelected(SelectionEvent event) {

    /*
     * Remember the example shells so they can be disposed by the user.
     */
    if (shellCount >= shells.length) {
        Shell[] newShells = new Shell[shells.length + 4];
        System.arraycopy(shells, 0, newShells, 0, shells.length);
        shells = newShells;
    }

    /* Compute the shell style */
    int style = SWT.NONE;
    if (noTrimButton.getSelection())
        style |= SWT.NO_TRIM;
    if (closeButton.getSelection())
        style |= SWT.CLOSE;
    if (titleButton.getSelection())
        style |= SWT.TITLE;
    if (minButton.getSelection())
        style |= SWT.MIN;
    if (maxButton.getSelection())
        style |= SWT.MAX;
    if (borderButton.getSelection())
        style |= SWT.BORDER;
    if (resizeButton.getSelection())
        style |= SWT.RESIZE;
    if (onTopButton.getSelection())
        style |= SWT.ON_TOP;
    if (toolButton.getSelection())
        style |= SWT.TOOL;
    if (modelessButton.getSelection())
        style |= SWT.MODELESS;
    if (primaryModalButton.getSelection())
        style |= SWT.PRIMARY_MODAL;
    if (applicationModalButton.getSelection())
        style |= SWT.APPLICATION_MODAL;
    if (systemModalButton.getSelection())
        style |= SWT.SYSTEM_MODAL;

    /* Create the shell with or without a parent */
    if (noParentButton.getSelection()) {
        shells[shellCount] = new Shell(style);
    } else {
        Shell shell = tabFolderPage.getShell();
        shells[shellCount] = new Shell(shell, style);
    }
    final Shell currentShell = shells[shellCount];
    Button button = new Button(currentShell, SWT.PUSH);
    button.setBounds(20, 20, 120, 30);
    Button closeButton = new Button(currentShell, SWT.PUSH);
    closeButton.setBounds(160, 20, 120, 30);
    closeButton.setText(ControlExample.getResourceString("Close"));
    closeButton.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event event) {
            currentShell.dispose();
        }
    });

    /* Set the size, title, and image, and open the shell */
    currentShell.setSize(300, 100);
    currentShell.setText(ControlExample.getResourceString("Title") + shellCount);
    if (imageButton.getSelection())
        currentShell.setImage(instance.images[ControlExample.ciTarget]);
    hookListeners(currentShell);
    currentShell.open();
    shellCount++;
}