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

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

    Button button = new Button(shell, SWT.NONE);
    button.setText("Click and check the console");
    button.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event e) {
            switch (e.type) {
            case SWT.Selection:
                System.out.println("Button pressed");
                break;
            }/*from   w w  w.  j a  va 2  s  . com*/
        }
    });

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

From source file:MenuCascade.java

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

    Button bn = new Button(shell, SWT.FLAT);
    bn.setText("Right Click to see the popup menu");

    Menu popupMenu = new Menu(bn);
    MenuItem newItem = new MenuItem(popupMenu, SWT.CASCADE);
    newItem.setText("New");
    MenuItem refreshItem = new MenuItem(popupMenu, SWT.NONE);
    refreshItem.setText("Refresh");
    MenuItem deleteItem = new MenuItem(popupMenu, SWT.NONE);
    deleteItem.setText("Delete");

    Menu newMenu = new Menu(popupMenu);
    newItem.setMenu(newMenu);/*  w w w  .j  ava2  s .  com*/

    MenuItem shortcutItem = new MenuItem(newMenu, SWT.NONE);
    shortcutItem.setText("Shortcut");
    MenuItem iconItem = new MenuItem(newMenu, SWT.NONE);
    iconItem.setText("Icon");

    bn.setMenu(popupMenu);

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

From source file:UntypedEventListener.java

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

    Button button = new Button(shell, SWT.NONE);
    button.setText("Click and check the console");
    button.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event e) {

            System.out.println(e.button);

            switch (e.type) {
            case SWT.Selection:
                System.out.println("Button pressed");
                break;
            }/*from   www. j a v  a 2s .  c o  m*/
        }
    });

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

From source file:ShellControlsGetting.java

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

    for (int i = 0; i < 20; i++) {
        Button button = new Button(shell, SWT.TOGGLE);
        button.setText("B" + i);
    }//from   w  w w . j av  a 2s .  c  o  m
    Control[] children = shell.getChildren();
    for (int i = 0; i < children.length; i++) {
        Control child = children[i];
        System.out.println(child);
    }

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

From source file:ButtonSelectionListener.java

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

    Button button = new Button(shell, SWT.NONE);
    button.setText("Click and check the console");
    button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {

            System.out.println("selection event");
        }/*w  w  w.  j  a v  a 2  s.c  o m*/
    });

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

From source file:ButtonImageAdd.java

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

    shell.setLayout(new FillLayout());

    Image image = new Image(display, "yourFile.gif");

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

    button.setImage(image);/*from  w ww.  j av  a  2s  .  c o m*/
    button.setText("button");

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

From source file:GenericEventUntyped.java

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

    Button button = new Button(shell, SWT.NONE);
    button.setText("Click and check the console");
    button.addSelectionListener(new SelectionListener() {
        public void widgetSelected(SelectionEvent arg0) {
            System.out.println("widgetSelected");
        }/*  w  w  w  .j a v  a  2s  .  c  om*/

        public void widgetDefaultSelected(SelectionEvent arg0) {
            System.out.println("widgetDefaultSelected");
        }
    });

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

From source file:EventModelPattern.java

public static void main(String[] args) {
    Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());

    Button button = new Button(shell, SWT.PUSH);
    button.setText("push me");
    button.addSelectionListener(new SelectionListener() {
        public void widgetDefaultSelected(SelectionEvent e) {
        }/*from   ww  w .  j  a v  a 2 s .co  m*/

        public void widgetSelected(SelectionEvent e) {
            System.out.println("Button pushed.");
        }
    });

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

From source file:RowLayoutDefaultValue.java

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

    RowLayout rowLayout = new RowLayout();

    shell.setLayout(rowLayout);//from w w w  . j a v  a  2  s  .c o m

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

    List list = new List(shell, SWT.BORDER);
    list.add("item 1");
    list.add("item 2");
    list.add("item 3");

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

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

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

From source file:DisplayEventFilerMouseDown.java

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

    Button button = new Button(shell, SWT.NONE);
    button.setText("Click and check the console");
    button.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event e) {
            switch (e.type) {
            case SWT.Selection:
                System.out.println("Button pressed");
                break;
            }/*from  w w  w.j a  v  a  2s .c o m*/
        }
    });

    display.addFilter(SWT.MouseDown, new SimpleListener("Display mouse down Listener"));

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