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

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

Introduction

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

Prototype

public void dispose() 

Source Link

Usage

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

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 60");
    shell.setSize(200, 200);/*from  w w w  .j av  a 2s  .  co m*/
    shell.open();
    display.timerExec(5000, () -> System.out.println("5000"));
    display.timerExec(2000, () -> System.out.println("2000"));
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:MainClass.java

public static void main(String[] a) {

    final Display d = new Display();
    final Shell shell = new Shell(d);

    shell.setSize(250, 200);//w w  w  .j  a v a  2  s .co m

    shell.setLayout(new FillLayout());

    Canvas drawingCanvas = new Canvas(shell, SWT.NONE);
    drawingCanvas.addPaintListener(new ArcExamplePaintListener());

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

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

public static void main(String[] args) {
    final String html = "<html><title>Snippet</title><body><p id='myid'>Best Friends</p><p id='myid2'>Cat and Dog</p></body></html>";
    Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("Snippet 161");
    shell.setLayout(new FillLayout());
    final Browser browser;
    try {/*from   w  ww  .  jav a  2 s  .co m*/
        browser = new Browser(shell, SWT.BORDER);
    } catch (SWTError e) {
        System.out.println("Could not instantiate Browser: " + e.getMessage());
        display.dispose();
        return;
    }
    Composite comp = new Composite(shell, SWT.NONE);
    comp.setLayout(new FillLayout(SWT.VERTICAL));
    final Text text = new Text(comp, SWT.MULTI);
    text.setText("var newNode = document.createElement('P'); \r\n"
            + "var text = document.createTextNode('At least when I am around');\r\n"
            + "newNode.appendChild(text);\r\n" + "document.getElementById('myid').appendChild(newNode);\r\n"
            + "\r\n" + "document.bgColor='yellow';");
    final Button button = new Button(comp, SWT.PUSH);
    button.setText("Execute Script");
    button.addListener(SWT.Selection, event -> {
        boolean result = browser.execute(text.getText());
        if (!result) {
            /* Script may fail or may not be supported on certain platforms. */
            System.out.println("Script was not executed.");
        }
    });
    browser.setText(html);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:FirstSWTClass.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("First SWT Application");
    shell.setSize(250, 250);/* w ww .  j  a  v  a  2s. c o  m*/
    Label label = new Label(shell, SWT.CENTER);
    label.setText("Greetings from SWT");
    label.setBounds(shell.getClientArea());
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:TextTextSelection.java

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

    final Text t = new Text(shell, SWT.BORDER | SWT.MULTI);
    t.setText("here is some text to be selected");

    t.selectAll();//from  w w  w . ja  va2  s  .c  o  m

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

From source file:Main.java

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

    shell.setLayout(new FillLayout());
    final FXCanvas canvas = new FXCanvas(shell, SWT.NONE);
    final Scene scene = TextIntegrationSceneCreator.createTextScene();
    canvas.setScene(scene);//from  ww w.j a  v  a2s. c  o m
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

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

public static void main(String[] args) {
    final String SCRIPT = "document.onmousedown = function(e) {if (!e) {e = window.event;} if (e) {mouseDownHappened(e.clientX, e.clientY);}}";
    Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("Snippet 362");
    shell.setLayout(new FillLayout());
    final Browser browser;
    try {/*from  www .  ja  v a2  s  .  c  o  m*/
        browser = new Browser(shell, SWT.NONE);
    } catch (SWTError e) {
        System.out.println("Could not instantiate Browser: " + e.getMessage());
        display.dispose();
        return;
    }
    browser.addProgressListener(ProgressListener.completedAdapter(event -> {
        final BrowserFunction function = new CustomFunction(browser, "mouseDownHappened");
        browser.execute(SCRIPT);
        browser.addLocationListener(new LocationAdapter() {
            @Override
            public void changed(LocationEvent event) {
                browser.removeLocationListener(this);
                function.dispose();
            }
        });
    }));

    browser.setUrl("eclipse.org");
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:FillLayoutVERTICAL.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new FillLayout(SWT.VERTICAL));
    new Button(shell, SWT.PUSH).setText("one");
    new Button(shell, SWT.PUSH).setText("two");
    new Button(shell, SWT.PUSH).setText("three");
    shell.open();//www  . j  a  v  a2 s  .  c  o  m
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    display.dispose();
}

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

public static void main(String[] args) {
    int maximumWidth = 200;
    int maximumHeight = 2000;

    String html = "<HTML><HEAD><TITLE>HTML Test</TITLE></HEAD><BODY>";
    for (int i = 0; i < 15; i++)
        html += "<P>This is line " + i + "</P>";
    html += "</BODY></HTML>";

    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 372");
    shell.setLayout(new FillLayout());
    Browser browser;// w  w  w. j  a  va  2  s .co m
    try {
        browser = new Browser(shell, SWT.NONE);
    } catch (SWTError e) {
        System.out.println("Could not instantiate Browser: " + e.getMessage());
        display.dispose();
        return;
    }
    browser.setText(html);
    browser.addProgressListener(ProgressListener.completedAdapter(event -> {
        // Set the display to something known to be smaller than the content
        shell.setSize(50, 50);
        browser.execute("document.getElementsByTagName(\"html\")[0].style.whiteSpace = \"nowrap\""); //$NON-NLS-1$
        // Save the width to either be a decided maximum or the browser's content width plus the margin
        Double width = Math.min(maximumWidth,
                10 + (Double) browser.evaluate("return document.body.scrollWidth;")); //$NON-NLS-1$
        shell.setSize(width.intValue(), 0);
        browser.execute("document.getElementsByTagName(\"html\")[0].style.whiteSpace = \"normal\""); //$NON-NLS-1$
        shell.layout();
        // Set the height to either be a decided maximum or the browser's content height plus the margin
        Double height = Math.min(maximumHeight,
                5 + (Double) browser.evaluate("return document.body.scrollHeight;")); //$NON-NLS-1$
        shell.setSize(width.intValue(), height.intValue());
    }));

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

From source file:FillLayoutHorizontal.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new FillLayout(SWT.HORIZONTAL));
    new Button(shell, SWT.PUSH).setText("one");
    new Button(shell, SWT.PUSH).setText("two");
    new Button(shell, SWT.PUSH).setText("three");
    shell.open();/*w w w .  j  a  v  a2s . c o m*/
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    display.dispose();
}