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

public static void main(String[] args) {

    Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());
    final Label label1 = new Label(shell, SWT.BORDER);
    label1.setText("TEXT");
    final Label label2 = new Label(shell, SWT.BORDER);
    setDragDrop(label1);//from www.  j  av  a2 s .co m
    setDragDrop(label2);
    shell.setSize(200, 200);
    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);// ww  w.  j  av a2s  .  c  o 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: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 . ja v a 2s.c o 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: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);//from   w w  w. ja  v  a 2 s . c om
    group.setBackgroundMode(SWT.INHERIT_NONE);

    shell.pack();
    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);
        }/* w  w  w . j av  a2 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   ww  w.j  ava 2s . c  o m
 * 
 * @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");

        }/*  w  w  w  . j  a  v  a 2  s .c  om*/
    });
    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);
        }/*from   w  w  w  .j a v a  2 s  .  com*/
    });

    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   w  w w  .  java 2 s.c om
        System.out.println("not center");
    }

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

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

From source file:DrawRoundRectangle.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.drawRoundRectangle(10, 10, 200, 200, 30, 30);
        }//from ww  w .  j a v a 2  s  . c o m
    });

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