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) {
    Display d = new Display();
    Shell s = new Shell(d);

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

    Menu m = new Menu(s, SWT.BAR);

    MenuItem file = new MenuItem(m, SWT.CASCADE);
    file.setText("File");
    Menu filemenu = new Menu(s, SWT.DROP_DOWN);
    file.setMenu(filemenu);/* w  w  w .  ja va2s.com*/
    MenuItem openItem = new MenuItem(filemenu, SWT.PUSH);
    openItem.setText("Open");
    MenuItem exitItem = new MenuItem(filemenu, SWT.PUSH);
    exitItem.setText("Exit");

    s.setMenuBar(m);

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

}

From source file:Snippet20.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    CoolBar bar = new CoolBar(shell, SWT.BORDER);
    for (int i = 0; i < 2; i++) {
        CoolItem item = new CoolItem(bar, SWT.NONE);
        Button button = new Button(bar, SWT.PUSH);
        button.setText("Button " + i);
        Point size = button.computeSize(SWT.DEFAULT, SWT.DEFAULT);
        item.setPreferredSize(item.computeSize(size.x, size.y));
        item.setControl(button);/*from w  w  w .  ja va 2 s. co  m*/
    }
    bar.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:RowLayoutDefaultValue.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 .j a v  a 2 s .  c o 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");

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

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

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

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

public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("Parent Shell");
    shell.addMouseListener(mouseDownAdapter(e -> {
        Shell dialog = new Shell(shell, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
        Point pt = display.getCursorLocation();
        dialog.setLocation(pt.x, pt.y);/*from  www. j  av  a2  s .  c  o  m*/
        dialog.setText("Dialog Shell");
        dialog.setSize(100, 100);
        dialog.open();
    }));
    shell.setSize(400, 400);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:GridLayoutDefaultValues.java

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

    GridLayout gridLayout = new GridLayout();

    shell.setLayout(gridLayout);/*from www.  ja v a  2s. c om*/

    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");

    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:ButtonWithEventListener.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) {
            switch (e.type) {
            case SWT.Selection:
                System.out.println("Button pressed");
                break;
            }//from ww w. j  av a2  s .com
        }
    });

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

From source file:AccessibleControlListenerAdding.java

License:asdf

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

    Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());

    Label label = new Label(shell, SWT.NONE);
    label.setText("asdf");

    Accessible accessible = label.getAccessible();
    accessible.addAccessibleControlListener(new AccessibleControlAdapter() {
        public void getState(AccessibleControlEvent e) {
            super.getState(e);
            System.out.println("AccessibleControlListener");
        }/*from w ww.  j  a va2  s .c  o  m*/
    });

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

    display.dispose();
}

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

    FormData formData = new FormData();
    formData.left = new FormAttachment(50);
    formData.right = new FormAttachment(100);
    formData.top = new FormAttachment(50);
    formData.bottom = new FormAttachment(100);

    button1.setLayoutData(formData);/*from   w  w  w. ja  v  a  2s  . c  om*/

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

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

From source file:ShellClosePrevent.java

public static void main(String[] args) {
    Display display = new Display();
    final Shell shell = new Shell(display);
    shell.addListener(SWT.Close, new Listener() {
        public void handleEvent(Event 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  .j a  v a  2  s .co m
    });
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:GroupImageAdding.java

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

    Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());
    Group group = new Group(shell, SWT.NONE);
    group.setLayout(new FillLayout());
    group.setText("a square");
    Canvas canvas = new Canvas(group, SWT.NONE);
    canvas.addPaintListener(new PaintListener() {
        public void paintControl(PaintEvent e) {
            e.gc.drawImage(new Image(display, "yourFile.gif"), 0, 0);
        }//  w w  w.ja  va2s.  c o m
    });

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

    display.dispose();
}