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

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

    GridLayout layout = new GridLayout(3, false);
    setLayout(layout);//from   ww w .j  av a 2 s. co m

    Button b = new Button(this, SWT.NONE);
    b.setText("Button 1");

    b = new Button(this, SWT.NONE);
    b.setText("Button 2");
    b.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    b = new Button(this, SWT.NONE);
    b.setText("Button 3");

    Text t = new Text(this, SWT.MULTI);
    GridData data = new GridData(GridData.FILL_BOTH);
    data.horizontalSpan = 2;
    data.verticalSpan = 2;
    t.setLayoutData(data);

    b = new Button(this, SWT.NONE);
    b.setText("Button 4");
    b.setLayoutData(new GridData(GridData.FILL_VERTICAL));

    b = new Button(this, SWT.NONE);
    b.setText("Button 5");
    b.setLayoutData(new GridData(GridData.FILL_VERTICAL));

}

From source file:RowLayoutExample.java

RowLayoutExample() {
    d = new Display();
    s = new Shell(d);
    s.setSize(250, 250);/*from w  w w  . j  av  a 2 s  . c  o  m*/

    s.setText("A RowLayout Example");
    s.setLayout(new RowLayout());
    final Text t = new Text(s, SWT.SINGLE | SWT.BORDER);
    final Button b = new Button(s, SWT.BORDER);
    final Button b1 = new Button(s, SWT.BORDER);
    b.setText("OK");
    b1.setText("Cancel");
    s.open();
    while (!s.isDisposed()) {
        if (!d.readAndDispatch())
            d.sleep();
    }
    d.dispose();
}

From source file:ArrowButtonExample.java

ArrowButtonExample() {
    d = new Display();
    s = new Shell(d);
    s.setSize(250, 250);//from   w  w  w .  j  av  a  2 s  . c om

    s.setText("A Button Example");
    final Button b1 = new Button(s, SWT.ARROW | SWT.UP);
    b1.setBounds(100, 55, 20, 15);
    final Button b2 = new Button(s, SWT.ARROW | SWT.DOWN);
    b2.setBounds(100, 70, 20, 15);
    final Text t1 = new Text(s, SWT.BORDER | SWT.SINGLE | SWT.CENTER);
    t1.setBounds(80, 55, 20, 30);
    t1.setText("1");
    t1.selectAll();
    b1.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            int n = new Integer(t1.getText()).intValue();
            n++;
            t1.setText(new Integer(n).toString());
            t1.selectAll();
        }
    });
    b2.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            int n = new Integer(t1.getText()).intValue();
            n--;
            t1.setText(new Integer(n).toString());
            t1.selectAll();
        }
    });
    s.open();
    while (!s.isDisposed()) {
        if (!d.readAndDispatch())
            d.sleep();
    }
    d.dispose();
}

From source file:MouseTrackExample.java

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

    s.setSize(250, 200);/*from www.  j  a v a  2  s.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:MouseMoveListenerExample.java

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

    s.setSize(250, 200);//w w w  .ja  v a2s.co m

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

    b.addMouseMoveListener(new MouseMoveListener() {
        public void mouseMove(MouseEvent e) {
            Random r = new Random(System.currentTimeMillis());
            Point p = s.getSize();
            int newX = r.nextInt(p.y);
            int newY = r.nextInt(p.x);
            b.setBounds(newX - 55, newY - 25, 55, 25);
        }

    });

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

From source file:Ch12ClipboardComposite.java

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

    FillLayout layout = new FillLayout();
    setLayout(layout);/*w w  w .  j  av a 2  s  .c  om*/

    Button b = new Button(this, SWT.NONE);
    b.setText("Copy to system clipboard");

    b.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            Clipboard clipboard = new Clipboard(getDisplay());
            String rtfData = "{\\rtf1\\b\\i Hello World}";
            RTFTransfer rtfTransfer = RTFTransfer.getInstance();
            clipboard.setContents(new Object[] { rtfData }, new Transfer[] { rtfTransfer });
            clipboard.dispose();
        }

        public void widgetDefaultSelected(SelectionEvent e) {
        }

    });

}

From source file:GroupShellExample2.java

GroupShellExample2() {
    d = new Display();
    s = new Shell(d);
    s.setSize(200, 200);/*  ww w .  ja  v a  2 s  .  co m*/

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

public ButtonStyles() {
    Display display = new Display();
    Shell shell = new Shell(display);

    shell.setLayout(new GridLayout(5, true));

    Button arrowButton = new Button(shell, SWT.ARROW);
    arrowButton.setText("&Arrow Button");

    Button checkButton = new Button(shell, SWT.CHECK);
    checkButton.setText("&Check Button");

    Button pushButton = new Button(shell, SWT.PUSH);
    pushButton.setText("&Push Button");

    Button radioButton = new Button(shell, SWT.RADIO);
    radioButton.setText("&Radio Button");

    Button toggleButton = new Button(shell, SWT.TOGGLE);
    toggleButton.setText("&Toggle Button");

    // shell.pack();
    shell.setSize(500, 100);//from   w  ww . j a  v a 2  s  .c o m
    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:ImageButton.java

public ImageButton() {
    //shell.setLayout(new RowLayout());

    Button button = new Button(shell, SWT.PUSH);
    button.setBounds(10, 10, 200, 200);//w w  w  . j a  va 2s  . c o m

    button.setImage(image);
    button.setText("button");

    System.out.println(button.getImage());

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

public MessageBoxExample() {
    button = new Button(shell, SWT.PUSH);

    button.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event event) {
            MessageBox messageBox = new MessageBox(shell,
                    SWT.ICON_WARNING | SWT.ABORT | SWT.RETRY | SWT.IGNORE);

            messageBox.setText("Warning");
            messageBox.setMessage("Save the changes before exiting?");
            int buttonID = messageBox.open();
            switch (buttonID) {
            case SWT.YES:
                // saves changes ...
            case SWT.NO:
                // exits here ...
                break;
            case SWT.CANCEL:
                // does nothing ...
            }//from  w w w.j  av a  2  s.c  om
            System.out.println(buttonID);
        }
    });

    button.setText("Click me!");

    button.setBounds(0, 0, 100, 30);

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