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:org.eclipse.swt.snippets.Snippet293.java

public static void main(java.lang.String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 293");
    shell.setLayout(new GridLayout());

    Button b1 = new Button(shell, SWT.CHECK);
    b1.setText("State 1");
    b1.setSelection(true);//from w w w  .j a  v  a 2  s  . c  o  m

    Button b2 = new Button(shell, SWT.CHECK);
    b2.setText("State 2");
    b2.setSelection(false);

    Button b3 = new Button(shell, SWT.CHECK);
    b3.setText("State 3");
    b3.setSelection(true);
    b3.setGrayed(true);

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

From source file:FontChangeSWT.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) {

            Font font = new Font(shell.getDisplay(), "Helvetica", 18, SWT.NORMAL);
            e.gc.setFont(font);//from   w  ww.  j  ava2  s  . c  o  m
            e.gc.drawText("My Text", 0, 0);
            font.dispose();

        }
    });

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

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

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 32");
    Label label = new Label(shell, SWT.NONE);
    label.setText("Can't find icon for .bmp");
    Image image = null;/*from  w w w . j a v a2s  .  c o m*/
    Program p = Program.findProgram(".bmp");
    if (p != null) {
        ImageData data = p.getImageData();
        if (data != null) {
            image = new Image(display, data);
            label.setImage(image);
        }
    }
    label.pack();
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    if (image != null)
        image.dispose();
    display.dispose();
}

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

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

    CCombo combo = new CCombo(shell, SWT.READ_ONLY | SWT.FLAT | SWT.BORDER);
    combo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    for (int i = 0; i < 5; i++) {
        combo.add("item" + i);
    }/*from  w  w  w. j  a va 2  s.  c o  m*/
    combo.setText("item0");

    combo.addSelectionListener(widgetSelectedAdapter(e -> System.out.println("Item selected")));

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

From source file:FormLayoutSingleLine.java

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

    Label label = new Label(shell, SWT.NONE | SWT.BORDER);
    label.setText("Name");

    Text text = new Text(shell, SWT.NONE);

    FormLayout layout = new FormLayout();
    layout.marginWidth = layout.marginHeight = 5;
    shell.setLayout(layout);//  w w  w  .  j  a v  a 2s .c o  m

    FormData data = new FormData(200, SWT.DEFAULT);
    text.setLayoutData(data);
    data.left = new FormAttachment(label, 5);
    data.top = new FormAttachment(label, 0, SWT.CENTER);

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

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 va2  s .c  o m

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

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

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

public static void main(String[] args) {
    Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("Media Player Example");
    shell.setLayout(new FillLayout());
    try {/*from   www.ja v  a2  s . co  m*/
        OleFrame frame = new OleFrame(shell, SWT.NONE);
        clientSite = new OleClientSite(frame, SWT.NONE, "MPlayer");
        addFileMenu(frame);
    } catch (SWTError e) {
        System.out.println("Unable to open activeX control");
        display.dispose();
        return;
    }
    shell.setSize(800, 600);
    shell.open();

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

From source file:RowLayoutRowData.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 .jav  a 2 s .  co  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");
    list.setLayoutData(new RowData(100, 35));

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

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

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

From source file:EventSelection.java

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

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

    button.setText("text on the button");

    button.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent arg0) {
            System.out.println("selected");
        }// w ww. j  av a2s  .  com

        public void widgetDefaultSelected(SelectionEvent arg0) {
        }
    });

    shell.open();
    // Set up the event loop.
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            // If no more entries in event queue
            display.sleep();
        }
    }
    display.dispose();
}

From source file:org.eclipse.swt.examples.layoutexample.LayoutExample.java

/**
 * Invokes as a standalone program.//from   w w w  .j a v a2  s .  c  om
 */
public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());
    new LayoutExample(shell);
    shell.setText(getResourceString("window.title"));
    shell.addShellListener(ShellListener.shellClosedAdapter(e -> {
        Shell[] shells = display.getShells();
        for (Shell currentShell : shells) {
            if (currentShell != shell)
                currentShell.close();
        }
    }));
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
}