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

public static void main(String[] args) {
    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.drawString("www.java2s.com", 5, 5);
        }/*from w w  w  .  j a  v a 2  s  .c o m*/
    });

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

From source file:ShellCenter.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setSize(200, 200);/*from   ww  w .jav  a2s.  co m*/

    Monitor primary = display.getPrimaryMonitor();
    Rectangle bounds = primary.getBounds();
    Rectangle rect = shell.getBounds();

    int x = bounds.x + (bounds.width - rect.width) / 2;
    int y = bounds.y + (bounds.height - rect.height) / 2;

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

From source file:BackgroundColorImageInherit.java

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

    shell.setLayout(new RowLayout(SWT.VERTICAL));

    Color color = display.getSystemColor(SWT.COLOR_CYAN);

    Group group = new Group(shell, SWT.NONE);
    group.setText("SWT.INHERIT_NONE");
    group.setBackground(color);/*  ww  w .  ja  va 2s.c  o  m*/
    group.setBackgroundMode(SWT.INHERIT_NONE);

    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) {
    Display display = new Display();
    final Shell shell = new Shell(display);

    Region region = new Region();
    region.add(createCircle(50, 50, 50));
    region.subtract(createCircle(50, 50, 20));
    shell.setRegion(region);/*from w w  w.  j a  v  a  2 s  .  co  m*/
    shell.setSize(region.getBounds().width, region.getBounds().height);
    shell.setBackground(display.getSystemColor(SWT.COLOR_BLUE));

    shell.open();

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

From source file:DrawStringLineTabSWT.java

public static void main(String[] args) {
    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.drawString("www.\njava2s\t.com", 5, 5);
        }//from  w w w .j ava2 s  . c o m
    });

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

From source file:MouseEventExample.java

/**
 * The application entry point/*from  w ww  .  j a  v a  2  s .c om*/
 * 
 * @param args the command line arguments
 */
public static void main(String[] args) {
    // Create the window
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new GridLayout());
    shell.setSize(450, 200);
    shell.setText("Mouse Event Example");

    // Create the listener
    MouseEventExample myMouseEventExample = new MouseEventExample(shell);

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

From source file:VerifyListenerUsing.java

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

    Text text = new Text(shell, SWT.SINGLE | SWT.BORDER);
    text.setText("Type somthing to verify.");
    text.addVerifyListener(new VerifyListener() {
        public void verifyText(VerifyEvent arg0) {
            System.out.println("verifying");

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

From source file:ControlListenerUsing.java

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

    shell.addControlListener(new ControlAdapter() {
        public void controlResized(ControlEvent event) {
            Shell shell = (Shell) event.getSource();
            Rectangle rect = shell.getClientArea();
            System.out.println(rect);
        }/*  w  w  w.  ja va 2 s  .  co m*/
    });

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

From source file:WidgetStyle.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    Label label = new Label(shell, SWT.SHADOW_IN | SWT.CENTER);

    shell.setLayout(new GridLayout());

    if ((label.getStyle() & SWT.CENTER) != 1) {
        System.out.println("center");
    } else {/*from  www. ja v  a  2s  . co  m*/
        System.out.println("not center");
    }

    shell.setSize(260, 120);
    shell.open();

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

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

public static void main(String[] args) {
    final Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 269");
    shell.setLayout(new FillLayout());
    Combo combo = new Combo(shell, SWT.NONE);
    combo.add("item");
    combo.select(0);/*  w  w  w . j ava  2s .  c  o m*/
    shell.pack();
    shell.open();
    int stringLength = combo.getText().length();
    combo.setSelection(new Point(stringLength, stringLength));
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}