Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[platform-swt-dev] How to wrap the SWT browser in multi-thread environment?

Hi all,

   I wrap the SWT browser in one thread, but the JRE crashes.
I can't figure that out.

Here is my code:

public class Demo implements Runnable {

    @Override
    public void run() {
        Display display = new Display();
        Shell shell = new Shell(display);
        shell.setLayout(new FillLayout());
        shell.setText("Mozilla");
        final Browser browser;
        try {
            browser = new Browser(shell, SWT.MOZILLA);
        } catch (SWTError e) {
            System.out.println("Could not instantiate Browser: " + e.getMessage());
            display.dispose();
            return;
        }
        shell.open();
        browser.setUrl("http://mozilla.org");
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch()) display.sleep();
        }
        display.dispose();
    }
   
    /**
     * @param args
     */
    public static void main(String[] args) {
        /*Invoke 2 threads*/

    }

}


Back to the top