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.Snippet35.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 35");
    Table table = new Table(shell, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    for (int i = 0; i < 12; i++) {
        TableItem item = new TableItem(table, 0);
        item.setText("Item " + i);
    }/*from   w  w w . j a  v  a 2s . co  m*/
    Rectangle clientArea = shell.getClientArea();
    table.setBounds(clientArea.x, clientArea.y, 100, 100);
    shell.setSize(200, 200);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

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

public static void main(String[] args) {
    Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("Snippet 99");
    shell.addListener(SWT.Close, event -> {
        int style = SWT.APPLICATION_MODAL | SWT.YES | SWT.NO;
        MessageBox messageBox = new MessageBox(shell, style);
        messageBox.setText("Information");
        messageBox.setMessage("Close the shell?");
        event.doit = messageBox.open() == SWT.YES;
    });//w  w  w .  jav a 2  s.c o  m
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:FileSaveDialogFilterNameFilterExtensions.java

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

    FileDialog dialog = new FileDialog(shell, SWT.SAVE);
    dialog.setFilterNames(new String[] { "Batch Files", "All Files (*.*)" });
    dialog.setFilterExtensions(new String[] { "*.bat", "*.*" }); // Windows
                                                                 // wild cards
    dialog.setFilterPath("c:\\"); // Windows path
    dialog.setFileName("yourFile.bat");
    System.out.println("Save to: " + dialog.open());
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();//ww w  .  ja  va2 s . c om
    }
    display.dispose();
}

From source file:FontSystemGettingSWT.java

public static void main(String[] args) {
    final 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.setFont(display.getSystemFont());

            e.gc.drawText(display.getSystemFont().getFontData()[0].getName(), 5, 5);
        }/*from w  ww . j a v  a2s.co  m*/
    });

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

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

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 302");
    FillLayout layout = new FillLayout();
    layout.marginHeight = 10;//from w ww .  jav  a 2 s .  co  m
    layout.marginWidth = 10;
    shell.setLayout(layout);
    Tree tree = new Tree(shell, SWT.BORDER | SWT.NO_SCROLL);
    for (int i = 0; i < 10; i++) {
        TreeItem item = new TreeItem(tree, SWT.NONE);
        item.setText("Item " + i);
    }
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:SliderMinMaxValue.java

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

    // Create a horizontal Slider, accepting the defaults
    new Slider(shell, SWT.HORIZONTAL);

    // Create a vertical Slider and set its properties
    Slider slider = new Slider(shell, SWT.VERTICAL);
    slider.setMinimum(0);//from www.java 2  s . c  o m
    slider.setMaximum(100);
    slider.setIncrement(5);
    slider.setPageIncrement(20);
    slider.setSelection(75);

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

From source file:SelectionStartEnd.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, 400, 100);//  w  w w. ja v a  2  s .com

    text.append("text text text text text text text text text text text text text ");

    shell.open();
    text.setSelection(30, 38);
    System.out.println("selection=" + text.getSelection());
    System.out.println("caret position=" + text.getCaretPosition());
    System.out.println("caret location=" + text.getCaretLocation());
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

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

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 52");
    Table table = new Table(shell, SWT.BORDER | SWT.MULTI);
    Rectangle clientArea = shell.getClientArea();
    table.setBounds(clientArea.x, clientArea.y, 200, 200);
    for (int i = 0; i < 128; i++) {
        TableItem item = new TableItem(table, SWT.NONE);
        item.setText("Item " + i);
    }/*from   ww w.j a  va 2 s  .  c  o  m*/
    table.setSelection(95);
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:Snippet40.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    Composite c1 = new Composite(shell, SWT.BORDER);
    c1.setSize(100, 100);/*  w  ww . j  a  v a 2s .  c o m*/
    Composite c2 = new Composite(shell, SWT.BORDER);
    c2.setBounds(100, 0, 100, 100);
    Menu menu = new Menu(shell, SWT.POP_UP);
    MenuItem item = new MenuItem(menu, SWT.PUSH);
    item.setText("Popup");
    c1.setMenu(menu);
    c2.setMenu(menu);
    shell.setMenu(menu);
    shell.setSize(300, 300);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

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

    shell.setLayout(new FillLayout());

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

    canvas.addPaintListener(new PaintListener() {
        public void paintControl(PaintEvent e) {

            e.gc.setForeground(e.display.getSystemColor(SWT.COLOR_BLACK));
            e.gc.drawOval(100, 20, 100, 50);

        }
    });

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