Example usage for org.eclipse.swt.widgets Display readAndDispatch

List of usage examples for org.eclipse.swt.widgets Display readAndDispatch

Introduction

In this page you can find the example usage for org.eclipse.swt.widgets Display readAndDispatch.

Prototype

public boolean readAndDispatch() 

Source Link

Document

Reads an event from the event queue, dispatches it appropriately, and returns true if there is potentially more work to do, or false if the caller can sleep until another event is placed on the event queue.

Usage

From source file:Snippet19.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    Text text = new Text(shell, SWT.BORDER | SWT.V_SCROLL);
    text.setBounds(10, 10, 200, 200);//w w  w.j a  v a2 s .c  om
    text.addListener(SWT.Verify, new Listener() {
        public void handleEvent(Event e) {
            String string = e.text;
            char[] chars = new char[string.length()];
            string.getChars(0, chars.length, chars, 0);
            for (int i = 0; i < chars.length; i++) {
                if (!('0' <= chars[i] && chars[i] <= '9')) {
                    e.doit = false;
                    return;
                }
            }
        }
    });
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:GridLayoutMargin.java

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

    GridLayout gridLayout = new GridLayout();
    gridLayout.marginHeight = 20;/*w w w  . ja v a  2  s.  com*/
    gridLayout.marginWidth = 30;

    shell.setLayout(gridLayout);

    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");

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

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

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

From source file:ImageCreateForLable.java

public static void main(String[] args) {
    Image image;//from w  w w  .  j a v  a  2 s  .  co m
    Image copy;
    Image disable;
    Image gray;

    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Show Image Flags");

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

    copy = new Image(display, image, SWT.IMAGE_COPY);

    disable = new Image(display, image, SWT.IMAGE_DISABLE);

    gray = new Image(display, image, SWT.IMAGE_GRAY);

    shell.setLayout(new FillLayout());

    // Create labels to hold each image
    new Label(shell, SWT.NONE).setImage(image);
    new Label(shell, SWT.NONE).setImage(copy);
    new Label(shell, SWT.NONE).setImage(disable);
    new Label(shell, SWT.NONE).setImage(gray);

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

    image.dispose();
    copy.dispose();
    disable.dispose();
    gray.dispose();

    display.dispose();

}

From source file:CoolBarComboButton.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    CoolBar bar = new CoolBar(shell, SWT.BORDER);

    CoolItem item = new CoolItem(bar, SWT.NONE);
    Button button = new Button(bar, SWT.PUSH);
    button.setText("Button ");
    Point size = button.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    item.setPreferredSize(item.computeSize(size.x, size.y));
    item.setControl(button);/*from   www .  j ava  2 s .  c  om*/

    item = new CoolItem(bar, SWT.NONE);
    Combo combo = new Combo(bar, SWT.NONE);
    size = combo.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    item.setPreferredSize(item.computeSize(size.x, size.y));
    item.setControl(combo);

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

From source file:org.eclipse.swt.snippets.Snippet164.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 164");
    shell.setLayout(new GridLayout());
    Image image = new Image(display, Snippet164.class.getResourceAsStream("eclipse.png"));

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

    Button button2 = new Button(shell, SWT.PUSH);
    button2.setImage(image);//from  w  w  w  .j  a v a 2s . c o  m
    button2.getAccessible().addAccessibleListener(new AccessibleAdapter() {
        @Override
        public void getName(AccessibleEvent e) {
            e.result = "Eclipse logo";
        }
    });

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

From source file:PopupListUsing.java

public static void main(String[] args) {
    Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("PopupList Test");
    shell.setLayout(new RowLayout());

    // Create a button to launch the list
    Button button = new Button(shell, SWT.PUSH);
    button.setText("Push Me");
    button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            PopupList list = new PopupList(shell);

            list.setItems(new String[] { "A", "B", "C" });

            String selected = list.open(shell.getBounds());
            System.out.println(selected);
        }/*from  w  w w  .j av  a 2  s  . c o m*/
    });

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

}

From source file:org.eclipse.swt.snippets.Snippet114.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 114");
    Tree tree = new Tree(shell, SWT.CHECK | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    for (int i = 0; i < 12; i++) {
        TreeItem item = new TreeItem(tree, SWT.NONE);
        item.setText("Item " + i);
    }//from  w  ww  .  jav  a2  s.  c o  m
    Rectangle clientArea = shell.getClientArea();
    tree.setBounds(clientArea.x, clientArea.y, 100, 100);
    tree.addListener(SWT.Selection, event -> {
        String string = event.detail == SWT.CHECK ? "Checked" : "Selected";
        System.out.println(event.item + " " + string);
    });
    shell.setSize(200, 200);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:GridLayoutSpacing.java

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

    GridLayout gridLayout = new GridLayout();
    gridLayout.horizontalSpacing = 20;//from  w  w  w  .j av a2 s. c o m
    gridLayout.verticalSpacing = 30;

    shell.setLayout(gridLayout);

    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");

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

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

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

From source file:SashFromMaximizeControl.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("SashForm Test");
    // Fill the parent window with the buttons and sash
    shell.setLayout(new FillLayout());

    // Create the SashForm and the buttons
    SashForm sashForm = new SashForm(shell, SWT.VERTICAL);
    new Button(sashForm, SWT.PUSH).setText("Left");
    Button control = new Button(sashForm, SWT.PUSH);
    control.setText("Right");
    sashForm.setOrientation(SWT.HORIZONTAL);

    if (control == sashForm.getMaximizedControl()) {
        sashForm.setMaximizedControl(null);
    } else {// w w  w.j a  va2 s .c  o m
        sashForm.setMaximizedControl(control);
    }

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

}

From source file:GridLayoutMakeColumnWidth.java

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

    GridLayout gridLayout = new GridLayout();
    gridLayout.numColumns = 2;/*from   ww  w .  j  a  v  a2 s.  c o m*/
    gridLayout.makeColumnsEqualWidth = true;

    shell.setLayout(gridLayout);

    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");

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

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

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