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

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

    Canvas canvas = new Canvas(shell, SWT.NONE);

    Button button = new Button(canvas, SWT.PUSH);
    button.setBounds(10, 10, 300, 40);//from  ww  w  .j av  a2 s .  c o  m
    button.setText("You can place widgets on a canvas");

    canvas.addPaintListener(new PaintListener() {
        public void paintControl(PaintEvent e) {
            Rectangle rect = ((Canvas) e.widget).getBounds();
            e.gc.setForeground(e.display.getSystemColor(SWT.COLOR_RED));
            e.gc.drawFocus(5, 5, rect.width - 10, rect.height - 10);
            e.gc.drawText("You can draw text directly on a canvas", 60, 60);
        }
    });

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

From source file:TabFolderSelectionEvent.java

public static void main(String[] args) {
    Display display = new Display();
    final Shell shell = new Shell(display);
    final TabFolder tabFolder = new TabFolder(shell, SWT.BORDER);
    for (int i = 0; i < 6; i++) {
        TabItem item = new TabItem(tabFolder, SWT.NONE);
        item.setText("TabItem " + i);
        Button button = new Button(tabFolder, SWT.PUSH);
        button.setText("Page " + i);
        item.setControl(button);//from  w  w w  .ja  v a 2s .  co m
    }

    // Add an event listener to write the selected tab to stdout
    tabFolder.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(org.eclipse.swt.events.SelectionEvent event) {
            System.out.println(tabFolder.getSelection()[0].getText() + " selected");
        }
    });

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

From source file:GroupExample.java

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

    // Create the first group
    Group group1 = new Group(shell, SWT.SHADOW_IN);
    group1.setText("Who's your favorite?");
    group1.setLayout(new RowLayout(SWT.VERTICAL));
    new Button(group1, SWT.RADIO).setText("John");
    new Button(group1, SWT.RADIO).setText("Paul");
    new Button(group1, SWT.RADIO).setText("George");
    new Button(group1, SWT.RADIO).setText("Ringo");

    // Create the second group
    Group group2 = new Group(shell, SWT.NO_RADIO_GROUP);
    group2.setText("Who's your favorite?");
    group2.setLayout(new RowLayout(SWT.VERTICAL));
    new Button(group2, SWT.RADIO).setText("Barry");
    new Button(group2, SWT.RADIO).setText("Robin");
    new Button(group2, SWT.RADIO).setText("Maurice");

    shell.open();//from w ww .j a va 2 s .c om
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    display.dispose();
}

From source file:LayoutSpaceProperties.java

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

    FillLayout fillLayout = new FillLayout(SWT.HORIZONTAL);

    fillLayout.marginWidth = 5;//from w  w w  .ja v  a  2s  . c om
    fillLayout.marginHeight = 5;

    // Number of pixels between the edge of a cell and edges of its neighboring cells
    fillLayout.spacing = 10;

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

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    StackLayout layout = new StackLayout();
    shell.setLayout(layout);/*from   w  w  w  .  ja v  a2  s  .com*/
    StackLayoutSelectionAdapter adapter = new StackLayoutSelectionAdapter(shell, layout);
    Button one = new Button(shell, SWT.PUSH);
    one.setText("one");
    one.addSelectionListener(adapter);
    Button two = new Button(shell, SWT.PUSH);
    two.setText("two");
    two.addSelectionListener(adapter);
    Button three = new Button(shell, SWT.PUSH);
    three.setText("three");
    three.addSelectionListener(adapter);
    layout.topControl = one;
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    display.dispose();
}

From source file:MainClass.java

public static void main(String[] a) {

    final Display d = new Display();
    final Shell shell = new Shell(d);

    shell.setSize(250, 200);//  ww  w  .  j  a  v a2 s  . c  om

    final String RUN = "Press to Run";
    final String IS_RUNNING = "Running...";

    shell.setLayout(new FillLayout());
    final Button button = new Button(shell, SWT.PUSH);
    button.setText(RUN);
    button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            button.setText(IS_RUNNING);

            BusyIndicator.showWhile(button.getDisplay(), new SleepThread(1000));

            button.setText(RUN);
        }
    });

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

}

From source file:DialogClass.java

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

    final Button button = new Button(shell, SWT.PUSH);
    button.setText("Delete File");
    button.setBounds(20, 40, 80, 25);

    final Text text = new Text(shell, SWT.SHADOW_IN);
    text.setBounds(140, 40, 100, 25);

    final Shell dialog = new Shell(shell, SWT.APPLICATION_MODAL | SWT.DIALOG_TRIM);
    dialog.setText("Delete File");
    dialog.setSize(250, 150);

    final Button buttonOK = new Button(dialog, SWT.PUSH);
    buttonOK.setText("OK");
    buttonOK.setBounds(20, 55, 80, 25);

    Button buttonCancel = new Button(dialog, SWT.PUSH);
    buttonCancel.setText("Cancel");
    buttonCancel.setBounds(120, 55, 80, 25);

    final Label label = new Label(dialog, SWT.NONE);
    label.setText("Delete the file?");
    label.setBounds(20, 15, 100, 20);

    Listener listener = new Listener() {
        public void handleEvent(Event event) {
            if (event.widget == buttonOK) {
                deleteFlag = true;
            } else {
                deleteFlag = false;
            }
            dialog.close();
        }
    };

    buttonOK.addListener(SWT.Selection, listener);
    buttonCancel.addListener(SWT.Selection, listener);

    Listener buttonListener = new Listener() {
        public void handleEvent(Event event) {
            dialog.open();
        }
    };

    button.addListener(SWT.Selection, buttonListener);

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

    if (deleteFlag) {
        text.setText("File deleted.");
    } else {
        text.setText("File not deleted.");
    }

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

From source file:MainClass.java

public static void main(String[] a) {

    final Display d = new Display();
    final Shell shell = new Shell(d);

    shell.setSize(250, 200);/*from w w  w.ja  va2s  .  c o m*/

    shell.setLayout(new FillLayout());

    ScrolledComposite sc = new ScrolledComposite(shell, SWT.H_SCROLL | SWT.V_SCROLL);

    Composite child = new Composite(sc, SWT.NONE);
    child.setLayout(new FillLayout());

    new Button(child, SWT.PUSH).setText("One");
    new Button(child, SWT.PUSH).setText("Two");
    sc.setContent(child);

    sc.setMinSize(300, 300);

    sc.setExpandHorizontal(true);
    sc.setExpandVertical(true);

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

From source file:Snippet4.java

public static void main(String[] args) {
    Display display = new Display();
    final Shell shell = new Shell(display);
    Button b = new Button(shell, SWT.PUSH);
    b.setText("Open Dialog ...");
    b.pack();// w w  w.  j a v  a2  s.c om
    b.setLocation(10, 10);
    b.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent se) {
            Shell dialog = new Shell(shell, SWT.DIALOG_TRIM);
            dialog.addListener(SWT.Traverse, new Listener() {
                public void handleEvent(Event e) {
                    if (e.detail == SWT.TRAVERSE_ESCAPE) {
                        e.doit = false;
                    }
                }
            });
            dialog.open();
        }
    });
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    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);//from www  . jav  a  2  s  .co 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 = 20;
    gridLayout.marginWidth = 20;
    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_HORIZONTAL);
    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, 15);
    data.left = new FormAttachment(one, 25);
    data.bottom = new FormAttachment(50, -15);
    data.right = new FormAttachment(100, -25);
    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();
}