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

public static void main(String[] a) {

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

    shell.setSize(250, 200);//from  ww  w.j av  a  2s  .com

    shell.setLayout(new RowLayout());

    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);
            String[] OPTIONS = { "A", "B", "C" };

            list.setItems(OPTIONS);

            String selected = list.open(shell.getBounds());

            System.out.println(selected);
        }
    });

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

From source file:Snippet113.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    Table table = new Table(shell, SWT.CHECK | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    for (int i = 0; i < 12; i++) {
        TableItem item = new TableItem(table, SWT.NONE);
        item.setText("Item " + i);
    }/* www.  j a va  2s  .  co m*/
    table.setSize(100, 100);
    table.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event 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:RadioNoGroup.java

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

    Menu menuBar = new Menu(shell, SWT.BAR);

    Menu fileMenu = new Menu(menuBar);

    MenuItem fileItem = new MenuItem(menuBar, SWT.CASCADE);
    fileItem.setText("File");
    fileItem.setMenu(fileMenu);/* www  .  j  a v a2  s .c  o m*/

    MenuItem itema = new MenuItem(fileMenu, SWT.RADIO);
    itema.setText("Radio A");
    MenuItem itemb = new MenuItem(fileMenu, SWT.RADIO);
    itemb.setText("Radio B");
    MenuItem itemc = new MenuItem(fileMenu, SWT.RADIO);
    itemc.setText("Radio C");

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

From source file:EventTypeGet.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(getEventName(e.type));
            switch (e.type) {
            case SWT.Selection:
                System.out.println("Button pressed");
                break;
            }//from   w  ww  .  ja v a2s  .  co m
        }
    });

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

From source file:ShellEscapeClose.java

public static void main(String[] args) {
    Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());
    shell.addListener(SWT.Traverse, new Listener() {
        public void handleEvent(Event event) {
            switch (event.detail) {
            case SWT.TRAVERSE_ESCAPE:
                shell.close();/*w  w  w.ja  v  a2 s  . c  o  m*/
                event.detail = SWT.TRAVERSE_NONE;
                event.doit = false;
                break;
            }
        }
    });
    Button button = new Button(shell, SWT.PUSH);
    button.setText("A Button (that doesn't process Escape)");
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:ImageCopyCreation.java

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

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

    canvas.addPaintListener(new PaintListener() {
        public void paintControl(PaintEvent e) {
            Image image = new Image(display, "yourFile.gif");

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

            e.gc.drawImage(copy, 10, 10);

            e.gc.drawImage(copy, 10, 50);

            image.dispose();//from  w w w  . ja  v a 2s  .  co  m
            copy.dispose();
        }
    });

    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);//w  w w  . j  a  va2  s  . c om

    s.setText("A Shell Composite Example");

    GridLayout gl = new GridLayout();
    gl.numColumns = 4;
    s.setLayout(gl);
    s.setLayout(gl);

    GridComposite gc = new GridComposite(s);
    GridData gd = new GridData(GridData.FILL_BOTH);
    gd.horizontalSpan = 4;
    gc.setLayoutData(gd);
    gd = new GridData();

    RowComposite rc = new RowComposite(s);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    rc.setLayoutData(gd);

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

From source file:org.eclipse.swt.examples.graphics.GraphicsExample.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new GraphicsExample().open(display);
    while (shell != null && !shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();/*from   ww w .ja  v a 2  s .  c  o m*/
    }
    display.dispose();
}

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

public static void main(String[] args) {
    Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("Snippet 197");
    final TextLayout layout = new TextLayout(display);
    layout.setText(longString);/* w  w w  .  jav  a 2  s. co m*/
    Listener listener = event -> {
        switch (event.type) {
        case SWT.Paint:
            layout.draw(event.gc, 10, 10);
            break;
        case SWT.Resize:
            layout.setWidth(shell.getSize().x - 20);
            break;
        }
    };
    shell.addListener(SWT.Paint, listener);
    shell.addListener(SWT.Resize, listener);
    shell.setSize(300, 300);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    layout.dispose();
    display.dispose();
}

From source file:MainClass.java

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

    s.setSize(250, 200);/*from w  w w .  j  a v a2s  .  co  m*/
    s.setText("A Table Shell Example");
    s.setLayout(new FillLayout());
    Tree t = new Tree(s, SWT.SINGLE | SWT.BORDER);
    TreeItem child1 = new TreeItem(t, SWT.NONE, 0);
    child1.setText("1");
    TreeItem child2 = new TreeItem(t, SWT.NONE, 1);
    child2.setText("2");
    TreeItem child2a = new TreeItem(child2, SWT.NONE, 0);
    child2a.setText("2A");
    TreeItem child2b = new TreeItem(child2, SWT.NONE, 1);
    child2b.setText("2B");
    TreeItem child3 = new TreeItem(t, SWT.NONE, 2);
    child3.setText("3");
    s.open();
    while (!s.isDisposed()) {
        if (!d.readAndDispatch())
            d.sleep();
    }
    d.dispose();

}