Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SWT Browser in eclipse plugin behaves differently in Mac and Windows

I'm using an SWT Browser in my Eclipse plug-in project. It shows a browser in a view that displays HTML generated locally. On Mac everything works fine. I can open a local link in the same browser using the code

browser.addOpenWindowListener(new OpenWindowListener() {
  public void open(WindowEvent event) {
    event.browser = browser;
    event.required = true;
  }
});

Now I want the same behavior on Windows, but I could never succeed. Nothing happens when I click on the link. And if I remove the listener, an Internet Explorer window opens when I click on the lick, not what I want.

I have seen that in windows the SWT Browser is using an IE style. And I have read posts on how to make Mozilla style Browser in windows. But I don't want users to do any extra setting or install anything else.

Does anyone have a solution?

EDIT: example code to show local html file

String url = "C:\\Users\\myname\\runtime-EclipseApplication\\tt\\target\\Results.html";
try {
  URI uri = new File(url).toURI();
  URL urls = uri.toURL();
  browser.setUrl(urls.toString());
} catch (MalformedURLException e) {
  e.printStackTrace();
}
like image 543
boreas Avatar asked Mar 21 '26 06:03

boreas


1 Answers

This works just fine here on Windows 7 using a Browser with SWT.NONE:

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

    final Shell shell = new Shell(display);
    shell.setText("StackOverflow");
    shell.setLayout(new FillLayout());

    Browser browser = new Browser(shell, SWT.NONE);

    String url = "start.html";
    try
    {
        URI uri = new File(url).toURI();
        URL urls = uri.toURL();
        browser.setUrl(urls.toString());
    }
    catch (MalformedURLException e)
    {
        e.printStackTrace();
    }

    shell.pack();
    shell.setSize(400, 300);
    shell.open();

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

    display.dispose();
}

This is the content of the start.html:

<a href="./test.html">Click here</a>

And the content of test.html:

<h1>HELLO</h1>
like image 155
Baz Avatar answered Mar 23 '26 18:03

Baz