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

public static void main(String[] args) {
    Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("Snippet 49");
    final ToolBar toolBar = new ToolBar(shell, SWT.WRAP);
    for (int i = 0; i < 12; i++) {
        ToolItem item = new ToolItem(toolBar, SWT.PUSH);
        item.setText("Item " + i);
    }// www.  ja  va  2s. co  m
    shell.addListener(SWT.Resize, e -> {
        Rectangle rect = shell.getClientArea();
        Point size = toolBar.computeSize(rect.width, SWT.DEFAULT);
        toolBar.setSize(size);
    });
    Rectangle clientArea = shell.getClientArea();
    toolBar.setLocation(clientArea.x, clientArea.y);
    toolBar.pack();
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

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

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

    FormData formData = new FormData();
    formData.left = new FormAttachment(button1);
    button2.setLayoutData(formData);//from   ww w.j a  va 2  s.c  o m

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

    formData = new FormData();
    formData.top = new FormAttachment(button2, 10);
    button3.setLayoutData(formData);

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

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

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

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 113");
    Table table = new Table(shell, SWT.CHECK | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    for (int i = 0; i < 12; i++) {
        TableItem item = new TableItem(table, SWT.NONE);
        item.setText("Item " + i);
    }/*from  w  w w  .  j a va2 s  .c o  m*/
    Rectangle clientArea = shell.getClientArea();
    table.setBounds(clientArea.x, clientArea.y, 100, 100);
    table.addListener(SWT.Selection, event -> {
        String string = event.detail == SWT.CHECK ? "Checked" : "Selected";
        System.out.println(event.item + " " + string);
    });
    shell.setSize(200, 200);
    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 single line text field
    new Text(shell, SWT.BORDER);

    // Create a right-aligned single line text field
    new Text(shell, SWT.RIGHT | SWT.BORDER);

    // Create a password text field
    new Text(shell, SWT.PASSWORD | SWT.BORDER);

    // Create a read-only text field
    new Text(shell, SWT.READ_ONLY | SWT.BORDER).setText("Read Only");

    // Create a multiple line text field
    Text t = new Text(shell, SWT.MULTI | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL);
    t.setLayoutData(new GridData(GridData.FILL_BOTH));

    shell.open();/*from   www  .ja v  a2s . co m*/
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    display.dispose();

}

From source file:MenuItemDiabled.java

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

    Menu menuBar = new Menu(shell, SWT.BAR);

    Menu fileMenu = new Menu(menuBar);

    MenuItem fileItem = new MenuItem(menuBar, SWT.CASCADE | SWT.NO_RADIO_GROUP);
    fileItem.setText("File");
    fileItem.setMenu(fileMenu);//w  ww .  j  a v a2 s.co m

    MenuItem itema = new MenuItem(fileMenu, SWT.NONE);
    itema.setText("Radio A");
    itema.setEnabled(false);
    MenuItem itemb = new MenuItem(fileMenu, SWT.NONE);
    itemb.setText("Radio B");
    MenuItem itemc = new MenuItem(fileMenu, SWT.NONE);
    itemc.setText("Radio C");

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

From source file:Snippet127.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    Button button1 = new Button(shell, SWT.PUSH);
    button1.setBounds(10, 10, 80, 30);//from   w w w .  ja  va  2 s  . com
    button1.setText("no traverse");
    button1.addTraverseListener(new TraverseListener() {
        public void keyTraversed(TraverseEvent e) {
            switch (e.detail) {
            case SWT.TRAVERSE_TAB_NEXT:
            case SWT.TRAVERSE_TAB_PREVIOUS: {
                e.doit = false;
            }
            }
        }
    });
    Button button2 = new Button(shell, SWT.PUSH);
    button2.setBounds(100, 10, 80, 30);
    button2.setText("can traverse");
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

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

    shell.addShellListener(new ShellListener() {

        public void shellActivated(ShellEvent event) {
            System.out.println("activate");
        }//  ww  w. j a va2 s .c  o m

        public void shellClosed(ShellEvent arg0) {
            System.out.println("close");
        }

        public void shellDeactivated(ShellEvent arg0) {
        }

        public void shellDeiconified(ShellEvent arg0) {
        }

        public void shellIconified(ShellEvent 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:Snippet53.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);// ww  w  .ja  v a2 s.  c o  m
    for (int i = 0; i < 128; i++) {
        TableItem item = new TableItem(table, SWT.NONE);
        item.setText("Item " + i);
    }
    Menu menu = new Menu(shell, SWT.POP_UP);
    table.setMenu(menu);
    MenuItem item = new MenuItem(menu, SWT.PUSH);
    item.setText("Delete Selection");
    item.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event event) {
            table.remove(table.getSelectionIndices());
        }
    });
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

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

public static void main(String[] args) {
    final Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 276");
    shell.setBounds(200, 200, 400, 400);
    Label label = new Label(shell, SWT.NONE);
    label.setText("click in shell to print display-relative coordinate");
    Listener listener = event -> {// w  w  w.  ja va 2 s .c o  m
        Point point = new Point(event.x, event.y);
        System.out.println(display.map((Control) event.widget, null, point));
    };
    shell.addListener(SWT.MouseDown, listener);
    label.addListener(SWT.MouseDown, listener);
    Rectangle clientArea = shell.getClientArea();
    label.setLocation(clientArea.x, clientArea.y);
    label.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}