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

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

    shell.setLayout(new FormLayout());

    Button button1 = new Button(shell, SWT.PUSH);
    button1.setText("button1");

    Point size = button1.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    int offset = size.x / 2;

    FormData formData = new FormData();
    formData.left = new FormAttachment(50, -1 * offset);

    button1.setLayoutData(formData);/*from   w w w  .  j ava  2  s. c  o m*/

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

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

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

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 301");
    FillLayout layout = new FillLayout();
    layout.marginHeight = 10;//from  w w w  . ja  v  a  2s  .c om
    layout.marginWidth = 10;
    shell.setLayout(layout);
    Table table = new Table(shell, SWT.BORDER | SWT.NO_SCROLL);
    for (int i = 0; i < 10; i++) {
        TableItem item = new TableItem(table, SWT.NONE);
        item.setText("Item " + i);
    }
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:TextEditor.java

public static void main(String[] args) {
    Display display = new Display();
    TextEditor example = new TextEditor();
    Shell shell = example.open(display);
    while (!shell.isDisposed())
        if (!display.readAndDispatch())
            display.sleep();/*from w w  w.j  av a  2 s . c  o  m*/
    display.dispose();
}

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

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

            image.dispose();/*from   w  w  w  .  j a  va  2s . c  om*/
        }
    });

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

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

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 184");
    Spinner spinner = new Spinner(shell, SWT.BORDER);
    spinner.setMinimum(0);//from  w ww  .  j  a  v a2 s .co  m
    spinner.setMaximum(1000);
    spinner.setSelection(500);
    spinner.setIncrement(1);
    spinner.setPageIncrement(100);
    Rectangle clientArea = shell.getClientArea();
    spinner.setLocation(clientArea.x, clientArea.y);
    spinner.pack();
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:MainClass.java

public static void main(String[] a) {
    final String[] ITEMS = { "A", "B", "C", "D", "E" };

    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new RowLayout());

    // Create a drop-down combo
    Combo combo = new Combo(shell, SWT.DROP_DOWN);
    combo.setItems(ITEMS);//from w  w  w .  j a v  a 2  s.co  m

    // Create a read only combo
    Combo readOnly = new Combo(shell, SWT.DROP_DOWN | SWT.READ_ONLY);
    readOnly.setItems(ITEMS);

    // Create a "simple" combo
    Combo simple = new Combo(shell, SWT.SIMPLE);
    simple.setItems(ITEMS);

    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();
    Shell shell = new Shell(display);
    shell.setLayout(new GridLayout(1, false));

    // 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   ww w . j  a  va  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:StyledTextVerifyListenerStopPasting.java

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

    StyledText styledText = new StyledText(shell, SWT.V_SCROLL | SWT.BORDER);
    styledText.setText("12345");

    styledText.addVerifyListener(new VerifyListener() {
        public void verifyText(VerifyEvent event) {
            if (event.text.length() > 1) {
                event.text = "Stop pasting!";
            }//w w  w.j av a2 s .  c  o  m

        }
    });

    styledText.setBounds(10, 10, 100, 100);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    display.dispose();
}

From source file:PopupMenuAddTwoControls.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);//from w w  w.  j  a va  2 s . c om

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

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

    // Create the first Group
    Group group1 = new Group(shell, SWT.SHADOW_IN);
    group1.setText("Who's your favorite?");
    group1.setLayout(new RowLayout(SWT.VERTICAL));
    new Button(group1, SWT.RADIO).setText("A");
    new Button(group1, SWT.RADIO).setText("B");
    new Button(group1, SWT.RADIO).setText("C");
    new Button(group1, SWT.RADIO).setText("D");

    shell.open();//from w  ww  . ja va2 s .c o  m
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    display.dispose();
}