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

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

    // Create three toggle buttons
    new Button(shell, SWT.TOGGLE).setText("Toggle 1");
    new Button(shell, SWT.TOGGLE).setText("Toggle 2");
    new Button(shell, SWT.TOGGLE).setText("Toggle 3");

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

From source file:MainClass.java

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

    DirectoryDialog dlg = new DirectoryDialog(shell);

    dlg.setFilterPath("c:/");

    dlg.setText("SWT's DirectoryDialog");

    dlg.setMessage("Select a directory");

    String dir = dlg.open();//  ww  w . j  av a2  s .  c o  m
    if (dir != null) {
        System.out.println(dir);
    }

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

From source file:Snippet12.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, 100, 100);/*from   ww  w.  j  ava 2  s  .c o m*/
    for (int i = 0; i < 16; i++) {
        text.append("Line " + i + "\n");
    }
    shell.open();
    text.setSelection(30, 38);
    System.out.println(text.getCaretLocation());
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:InputDialog.java

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

    InputDialog dlg = new InputDialog(shell);
    String input = dlg.open();//ww w .  j  a v a  2s.  c  o m
    if (input != null) {
        // User clicked OK; set the text into the label
        System.out.println(input);
    }

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

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

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 370");
    shell.setLayout(new RowLayout(SWT.VERTICAL));
    Locale[] locales = Locale.getAvailableLocales();
    for (Locale locale : locales) {
        createForLocale(shell, locale);//from w ww .  jav  a  2 s . com
    }
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:GCBackgroundForeground.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.open();/*from  w  ww .j a  v a 2 s .  c  o  m*/

    Color white = display.getSystemColor(SWT.COLOR_WHITE);
    Color black = display.getSystemColor(SWT.COLOR_BLACK);

    GC gc = new GC(shell);
    gc.setBackground(black);
    gc.setForeground(white);

    gc.drawString("Test", 12, 12);

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

    display.dispose();
}

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

public static void main(String[] args) {
    Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("Snippet 23");
    shell.open();/* w  ww .j a va  2  s  .  c o m*/
    shell.addListener(SWT.MouseDown, e -> {
        Tracker tracker = new Tracker(shell, SWT.NONE);
        tracker.setRectangles(new Rectangle[] { new Rectangle(e.x, e.y, 100, 100), });
        tracker.open();
    });
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

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

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 26");
    Combo combo = new Combo(shell, SWT.READ_ONLY);
    combo.setItems("Alpha", "Bravo", "Charlie");
    Rectangle clientArea = shell.getClientArea();
    combo.setBounds(clientArea.x, clientArea.y, 200, 200);
    shell.pack();//from  www . j  a  v a2s .  c  o m
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:SelectRangeList.java

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

    // Create a multiple-selection list
    List multi = new List(shell, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL);

    // Add the items all at once
    multi.setItems(ITEMS);//from  w ww.ja v a2s  .  c  o m

    // Select a range
    multi.select(0, 2);

    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.  j a v  a 2s  .c o  m*/
    s.setText("A Combo Example");

    s.setText("A List Example");
    String items[] = { "Item One", "Item Two", "Item Three", "Item Four", "Item Five" };
    final List l = new List(s, SWT.SINGLE | SWT.BORDER);
    l.setBounds(50, 50, 75, 75);
    l.setItems(items);

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