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

public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display);
    final Button button = new Button(shell, SWT.NONE);
    button.setSize(100, 100);/*from  w  ww  . j a  v  a 2  s. co m*/
    button.setText("Click");
    shell.pack();
    shell.open();
    button.addListener(SWT.MouseDown, new Listener() {
        public void handleEvent(Event e) {
            System.out.println("Mouse Down (button: " + e.button + " x: " + e.x + " y: " + e.y + ")");
        }
    });
    final Point pt = display.map(shell, null, 50, 50);
    new Thread() {
        Event event;

        public void run() {
            try {
                Thread.sleep(300);
            } catch (InterruptedException e) {
            }
            event = new Event();
            event.type = SWT.MouseMove;
            event.x = pt.x;
            event.y = pt.y;
            display.post(event);
            try {
                Thread.sleep(300);
            } catch (InterruptedException e) {
            }
            event.type = SWT.MouseDown;
            event.button = 1;
            display.post(event);
            try {
                Thread.sleep(300);
            } catch (InterruptedException e) {
            }
            event.type = SWT.MouseUp;
            display.post(event);
        }
    }.start();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:MarginSpaceProperties.java

public static void main(String[] args) {
    Display display = new Display();
    final Shell shell = new Shell(display);

    FillLayout fillLayout = new FillLayout(SWT.HORIZONTAL);

    // Width of horizontal margins placed along the left and right edges    
    fillLayout.marginWidth = 5;/*from w  w  w  .  j  a va 2  s  . c  o m*/
    // Height of vertical margins placed along the top and bottom edges
    fillLayout.marginHeight = 5;

    shell.setLayout(fillLayout);

    Button button1 = new Button(shell, SWT.PUSH);
    button1.setText("button1");

    Button button2 = new Button(shell, SWT.PUSH);
    button2.setText("button number 2");

    Button button3 = new Button(shell, SWT.PUSH);
    button3.setText("3");

    shell.setSize(450, 100);
    shell.open();

    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    display.dispose();
}

From source file:ButtonClass.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setSize(200, 200);/*from  ww  w.ja v a 2 s. c  o  m*/
    shell.setText("Button Example");

    final Button button = new Button(shell, SWT.PUSH);
    button.setBounds(40, 50, 50, 20);
    button.setText("Click Me");

    final Text text = new Text(shell, SWT.BORDER);
    text.setBounds(100, 50, 70, 20);

    button.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent event) {
            text.setText("No problem");
        }

        public void widgetDefaultSelected(SelectionEvent event) {
            text.setText("No worries!");
        }
    });

    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:MainClass.java

public static void main(String[] a) {
    Display d = new Display();
    Shell s = new Shell(d);

    s.setText("A Tabbed Shell Example");
    final CoolBar bar = new CoolBar(s, SWT.BORDER);
    bar.setSize(280, 70);/*  ww w .ja  va  2  s  .c om*/
    bar.setLocation(0, 0);
    // final Image openIcon = new Image(d, "c:\\icons\\open.jpg");

    final CoolItem openCoolItem = new CoolItem(bar, SWT.NONE);
    final Button openBtn = new Button(bar, SWT.PUSH);
    // openBtn.setImage(openIcon);
    openBtn.pack();
    Point size = openBtn.getSize();
    openCoolItem.setControl(openBtn);
    openCoolItem.setSize(openCoolItem.computeSize(size.x, size.y));

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

From source file:ButtonDefaultShell.java

public static void main(String[] args) {
    final Display display = new Display();
    Shell shell = new Shell(display);

    shell.setLayout(new RowLayout());

    final String[] ratings = new String[] { "A!", "B", "C" };
    final Button[] radios = new Button[ratings.length];
    for (int i = 0; i < ratings.length; i++) {
        radios[i] = new Button(shell, SWT.RADIO);
        radios[i].setText(ratings[i]);//from  w ww. j  a  v  a  2  s  .  c o  m
    }

    Button cancelButton = new Button(shell, SWT.PUSH);
    cancelButton.setText("Canel");

    Button rateButton = new Button(shell, SWT.PUSH);
    rateButton.setText("OK");
    rateButton.addSelectionListener(new SelectionListener() {
        public void widgetSelected(SelectionEvent e) {
            for (int i = 0; i < radios.length; i++) {
                if (radios[i].getSelection()) {
                    System.out.println(ratings[i]);
                }
            }
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            for (int i = 0; i < radios.length; i++) {
                if (radios[i].getSelection()) {
                    System.out.println(ratings[i]);
                }
            }
        }
    });

    shell.setDefaultButton(rateButton);

    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
}

From source file:Snippet44.java

public static void main(String[] args) {
    Display display = new Display();
    final Cursor cursor = new Cursor(display, SWT.CURSOR_HAND);
    Shell shell = new Shell(display);
    shell.open();//  ww  w.j a  v  a2s.  c o  m
    final Button b = new Button(shell, 0);
    b.setBounds(10, 10, 200, 200);
    b.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event e) {
            b.setCursor(cursor);
        }
    });
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    cursor.dispose();
    display.dispose();
}

From source file:FormLayoutComplex.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    FormLayout layout = new FormLayout();
    shell.setLayout(layout);/*  w w  w. ja va2 s.  c  o m*/
    Button one = new Button(shell, SWT.PUSH);
    one.setText("One");
    FormData data = new FormData();
    data.top = new FormAttachment(0, 5);
    data.left = new FormAttachment(0, 5);
    data.bottom = new FormAttachment(50, -5);
    data.right = new FormAttachment(50, -5);
    one.setLayoutData(data);

    Composite composite = new Composite(shell, SWT.NONE);
    GridLayout gridLayout = new GridLayout();
    gridLayout.marginHeight = 0;
    gridLayout.marginWidth = 0;
    composite.setLayout(gridLayout);
    Button two = new Button(composite, SWT.PUSH);
    two.setText("two");
    GridData gridData = new GridData(GridData.FILL_BOTH);
    two.setLayoutData(gridData);
    Button three = new Button(composite, SWT.PUSH);
    three.setText("three");
    gridData = new GridData(GridData.FILL_BOTH);
    three.setLayoutData(gridData);
    Button four = new Button(composite, SWT.PUSH);
    four.setText("four");
    gridData = new GridData(GridData.FILL_BOTH);
    four.setLayoutData(gridData);
    data = new FormData();
    data.top = new FormAttachment(0, 5);
    data.left = new FormAttachment(one, 5);
    data.bottom = new FormAttachment(50, -5);
    data.right = new FormAttachment(100, -5);
    composite.setLayoutData(data);

    Button five = new Button(shell, SWT.PUSH);
    five.setText("five");
    data = new FormData();
    data.top = new FormAttachment(one, 5);
    data.left = new FormAttachment(0, 5);
    data.bottom = new FormAttachment(100, -5);
    data.right = new FormAttachment(100, -5);
    five.setLayoutData(data);

    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    display.dispose();
}

From source file:MainClass.java

public static void main(String[] a) {
    Display d = new Display();
    Shell s = new Shell(d);

    s.setSize(250, 250);/*from w w w  .java2  s.  c  o m*/
    s.setText("A List Example");
    final List l = new List(s, SWT.MULTI | SWT.BORDER);
    l.setBounds(50, 50, 75, 75);
    l.add("Item One");
    l.add("Item Two");
    l.add("Item Three");
    l.add("Item Four");
    l.add("Item Five");
    final Button b1 = new Button(s, SWT.PUSH | SWT.BORDER);
    b1.setBounds(150, 150, 50, 25);
    b1.setText("Click Me");
    b1.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            String selected[] = l.getSelection();
            for (int i = 0; i < selected.length; i++) {
                System.out.println(selected[i]);
            }
        }
    });

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

From source file:GridLayoutFillBoth.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    GridLayout layout = new GridLayout();
    layout.numColumns = 3;/*  w ww .  java 2  s. c  o m*/
    layout.makeColumnsEqualWidth = true;
    shell.setLayout(layout);

    // Create the big button in the upper left
    GridData data = new GridData(GridData.FILL_BOTH);
    data.widthHint = 200;
    Button one = new Button(shell, SWT.PUSH);
    one.setText("one");
    one.setLayoutData(data);

    // Create a composite to hold the three buttons in the upper right
    Composite composite = new Composite(shell, SWT.NONE);

    // Create button "two"
    data = new GridData(GridData.FILL_BOTH);
    Button two = new Button(composite, SWT.PUSH);
    two.setText("two");
    two.setLayoutData(data);

    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    display.dispose();
}

From source file:GridLayoutComplex.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    GridLayout layout = new GridLayout();
    layout.numColumns = 3;/* ww w. j a v a  2s. c o  m*/
    layout.makeColumnsEqualWidth = true;
    shell.setLayout(layout);

    // Create the big button in the upper left
    GridData data = new GridData(GridData.FILL_BOTH);
    data.widthHint = 200;
    Button one = new Button(shell, SWT.PUSH);
    one.setText("one");
    one.setLayoutData(data);

    // Create a composite to hold the three buttons in the upper right
    Composite composite = new Composite(shell, SWT.NONE);
    data = new GridData(GridData.FILL_BOTH);
    data.horizontalSpan = 2;
    composite.setLayoutData(data);
    layout = new GridLayout();
    layout.numColumns = 1;
    layout.marginHeight = 15;
    composite.setLayout(layout);

    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    display.dispose();
}