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

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    Link link = new Link(shell, SWT.NONE);
    String text = "The SWT component is designed to provide <a>efficient</a>, <a>portable</a> <a href=\"native\">access to the user-interface facilities of the operating systems</a> on which it is implemented.";
    link.setText(text);//from ww w. j  a  va 2s  .co  m
    link.setSize(400, 400);
    link.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event event) {
            System.out.println("Selection: " + event.text);
        }
    });
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:ReplaceStyleRanges.java

License:asdf

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

    final StyledText styledText = new StyledText(shell, SWT.V_SCROLL | SWT.BORDER);
    styledText.setText("asdfasdfasdfasdf12345678910234567890");

    StyleRange[] ranges = new StyleRange[2];
    ranges[0] = new StyleRange(0, 3, display.getSystemColor(SWT.COLOR_GREEN), null);
    ranges[1] = new StyleRange(3, 6, display.getSystemColor(SWT.COLOR_BLUE), null);

    styledText.setStyleRanges(ranges);//from   www.  j  a v a 2  s. c o  m

    styledText.replaceStyleRanges(5, 9, ranges);

    styledText.setBounds(10, 10, 500, 100);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    display.dispose();
}

From source file:StyledTextVerifyListenerReturn.java

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

    StyledText styledText = new StyledText(shell, SWT.V_SCROLL | SWT.BORDER);
    styledText.setText("12345");

    styledText.addVerifyKeyListener(new VerifyKeyListener() {

        public void verifyKey(VerifyEvent event) {
            System.out.println(event.character);
            event.doit = false;//  ww  w  .j  av a2s .c om

            // Allow return
            if (event.character == '\r')
                event.doit = true;
        }
    });

    styledText.setBounds(10, 10, 100, 100);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    display.dispose();

}

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

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 127");
    shell.setLayout(new RowLayout());
    Button button1 = new Button(shell, SWT.PUSH);
    button1.setText("Can't Traverse");
    button1.addTraverseListener(e -> {
        switch (e.detail) {
        case SWT.TRAVERSE_TAB_NEXT:
        case SWT.TRAVERSE_TAB_PREVIOUS: {
            e.doit = false;/*ww  w  .ja  va 2  s .c  o  m*/
        }
        }
    });
    Button button2 = new Button(shell, SWT.PUSH);
    button2.setText("Can Traverse");
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:BrowserExample.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());
    shell.setText("Browser example");
    BrowserExample instance = new BrowserExample(shell);
    Image icon = new Image(display, "java2s.gif");
    shell.setImage(icon);//  w  ww  . j  a v  a 2s.c o  m
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    icon.dispose();
    instance.dispose();
    display.dispose();
}

From source file:OpenWindowListenerUsing.java

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

    Browser browser = new Browser(shell, SWT.NONE);
    browser.setBounds(5, 5, 600, 600);//from  ww  w . j a v  a2s  .c om

    browser.addOpenWindowListener(new OpenWindowListener() {
        public void open(WindowEvent event) {
            Shell shell = new Shell(display);
            shell.setText("New Window");
            shell.setLayout(new FillLayout());
            Browser browser = new Browser(shell, SWT.NONE);
            event.browser = browser;
        }
    });

    browser.setUrl("http://java2s.com");
    shell.open();

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

From source file:ImageDataFromImage.java

public static void main(String[] args) {
    final Display display = new Display();
    final 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) {
            Image image = new Image(display, "yourFile.gif");

            ImageData data = image.getImageData();

            System.out.println(data.height);

            e.gc.drawImage(image, 10, 10);
            image.dispose();/*www .  jav  a2 s  . c om*/
        }
    });

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

From source file:SpinnerFloatPoint.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Spinner with float values");
    shell.setLayout(new GridLayout());
    final Spinner spinner = new Spinner(shell, SWT.NONE);
    // allow 3 decimal places
    spinner.setDigits(3);/*  w w  w .j  a  v  a 2s. com*/
    // set the minimum value to 0.001
    spinner.setMinimum(1);
    // set the maximum value to 20
    spinner.setMaximum(20000);
    // set the increment value to 0.010
    spinner.setIncrement(10);
    // set the seletion to 3.456
    spinner.setSelection(3456);
    shell.setSize(200, 200);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

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

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Main Window");
    shell.setLayout(new FillLayout());
    final Browser browser;
    try {//w w w . j  a  v  a  2s  .c om
        browser = new Browser(shell, BROWSER_STYLE);
    } catch (SWTError e) {
        System.out.println("Could not instantiate Browser: " + e.getMessage());
        display.dispose();
        return;
    }
    initialize(display, browser);
    shell.open();
    browser.setUrl("http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_win_open");
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:ImageEmpty.java

public static void main(String[] args) {
    final Display display = new Display();
    final 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) {
            Image image = new Image(display, 300, 200);
            GC gc = new GC(image);
            gc.drawLine(10, 10, 200, 200);
            gc.dispose();//from ww w  . j a  va  2  s.  com

            e.gc.drawImage(image, 10, 10);
            image.dispose();
        }
    });

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