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

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

    GridLayout layout = new GridLayout();
    layout.numColumns = 2;// w w w.  ja  va  2 s.c o m
    shell.setLayout(layout);
    new Button(shell, SWT.PUSH).setText("one");
    new Button(shell, SWT.PUSH).setText("two");
    new Button(shell, SWT.PUSH).setText("three");
    new Button(shell, SWT.PUSH).setText("four");

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

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

public static void main(String[] args) {
    final Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 269");
    shell.setLayout(new FillLayout());
    Combo combo = new Combo(shell, SWT.NONE);
    combo.add("item");
    combo.select(0);//from  www .  ja  va  2 s. co m
    shell.pack();
    shell.open();
    int stringLength = combo.getText().length();
    combo.setSelection(new Point(stringLength, stringLength));
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:Snippet55.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    Text text = new Text(shell, SWT.BORDER);
    int columns = 10;
    GC gc = new GC(text);
    FontMetrics fm = gc.getFontMetrics();
    int width = columns * fm.getAverageCharWidth();
    int height = fm.getHeight();
    gc.dispose();/* w w w .j a v  a 2  s  . c  o  m*/
    text.setSize(text.computeSize(width, height));
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:ModifyListenerUsing.java

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

    Text text = new Text(shell, SWT.SINGLE | SWT.BORDER);
    text.setText("Type somthing to modify.");
    text.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent arg0) {
            System.out.println("Text modified");

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

From source file:DrawOval.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);

    canvas.addPaintListener(new PaintListener() {
        public void paintControl(PaintEvent e) {
            e.gc.drawOval(200, 100, 500, 400);
        }/*ww w .ja v a  2s  . co m*/
    });

    canvas.redraw();

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

From source file:MainClass.java

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

    PrintDialog dlg = new PrintDialog(shell);

    dlg.setScope(PrinterData.SELECTION);

    PrinterData printerData = dlg.open();
    if (printerData != null) {

        System.out.println(printerData.printToFile);

        // Printer printer = new Printer(printerData);
        // Use printer . . .
        // printer.dispose();
    }/*from w w w . j  av a 2s .  c o  m*/

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

From source file:TableRowSelectionRemove.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    final Table table = new Table(shell, SWT.BORDER | SWT.MULTI);
    table.setSize(200, 200);/*from  w w w  . j  av  a  2 s  .  c om*/
    for (int i = 0; i < 128; i++) {
        TableItem item = new TableItem(table, SWT.NONE);
        item.setText("Item " + i);
    }

    table.setSelection(2);

    table.remove(table.getSelectionIndices());

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

From source file:HoverHelp.java

/**
 * Runs main program./* w  w w.jav  a 2  s  .  c  o m*/
 */
public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new HoverHelp().open(display);
    // Event loop
    while (shell != null && !shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    // Cleanup
    display.dispose();

}

From source file:ButtonSelectionListener.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 SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {

            System.out.println("selection event");
        }//from  w  w w. j  a v  a 2s  .  c  o  m
    });

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

From source file:MainClass.java

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

    s.setSize(250, 200);/*from w  ww . j a v a 2s.c o  m*/
    s.setText("A MouseListener Example");
    final Button b = new Button(s, SWT.PUSH);
    b.setText("Push Me");
    b.setBounds(20, 50, 55, 25);
    s.open();

    b.addMouseMoveListener(new MouseMoveListener() {
        public void mouseMove(MouseEvent e) {
            System.out.println(e.x);
        }
    });

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

}