Example usage for org.eclipse.swt.widgets Display sleep

List of usage examples for org.eclipse.swt.widgets Display sleep

Introduction

In this page you can find the example usage for org.eclipse.swt.widgets Display sleep.

Prototype

public boolean sleep() 

Source Link

Document

Causes the user-interface thread to sleep (that is, to be put in a state where it does not consume CPU cycles) until an event is received or it is otherwise awakened.

Usage

From source file:GridLayoutMakeColumnWidth.java

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

    GridLayout gridLayout = new GridLayout();
    gridLayout.numColumns = 2;//  w w w . ja v a 2s .  c o m
    gridLayout.makeColumnsEqualWidth = true;

    shell.setLayout(gridLayout);

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

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

    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.ja v  a  2s  .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: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 w  ww. 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: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();// w  w  w  .  ja va  2s  .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  w w .  ja  v a 2s  .  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);//  w  w w  .j a v a  2 s  .  c o  m
    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: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. j  av a  2s .  c  om
    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 -> {//from  w  w w. j  av  a 2s  .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();
}

From source file:TreeItemMousePostion.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    final Tree tree = new Tree(shell, SWT.BORDER | SWT.MULTI);
    for (int i = 0; i < 12; i++) {
        TreeItem treeItem = new TreeItem(tree, SWT.NONE);
        treeItem.setText("Item " + i);
    }/*ww w. j  a  va 2 s  . c om*/
    tree.addListener(SWT.MouseDown, new Listener() {
        public void handleEvent(Event event) {
            Point point = new Point(event.x, event.y);
            TreeItem item = tree.getItem(point);
            if (item != null) {
                System.out.println("Mouse down: " + item);
            }
        }
    });
    tree.setSize(200, 200);
    shell.setSize(300, 300);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}