SWT on different systems

2019-09-16 02:42发布

问题:

I used Java and SWT's Browser. I prepare two system versions of application, first for OSX second for Windows.

Both systems are 64bit

SWT need different libraries for different systems so in Maven I declared both

<profile>
    <id>windows-deploy</id>

    <dependencies>
        <dependency>
            <groupId>org.eclipse.swt</groupId>
            <artifactId>org.eclipse.swt.win32.win32.x86_64</artifactId>
            <version>4.6.1</version>
        </dependency>
    </dependencies>
</profile>

<profile>
    <id>osx-deploy</id>

    <dependencies>
        <dependency>
            <groupId>org.eclipse.swt</groupId>
            <artifactId>org.eclipse.swt.cocoa.macosx.x86_64</artifactId>
            <version>4.6.1</version>
        </dependency>
    </dependencies>
</profile>

In the browser I load page and click button (which creates new window) but I do not want open new window, only reload actual browser which new page, I did it like in code below

browser.addOpenWindowListener(new OpenWindowListener() {
    public void open(WindowEvent event) {
        Log.debug(TAG + "<>", "Open new page!");
        event.browser = browser;
    }
 });

And on OS X system it works great.

But when I try on Windows, after click on button old page do not change. I checked Logs and the message "Open new page!" was written but nothing happens (new page do not load like in OS X). I though that can be something about refreshing after load page by WebKit and browser.refresh() refresh browser but there is old content (not new like in OS X).

I debug and checked what happens after event.browser = browser; the WebKit from SWT library take control.

What I should do to get the same effect on Windows like on OS X ?

回答1:

RESOLVED

Problem is in libraries. On OSX system when we change event.browser object, is automatically detected and it working, but on Windows system we need to add to browser VisibilityWindowListener as in code fragment below and working fine :)

browser.addVisibilityWindowListener(new VisibilityWindowListener() {
            public void hide(WindowEvent event) {
            }

            public void show(WindowEvent event) {
                Browser browser = (Browser) event.widget;
                Shell shell = browser.getShell();

                if (event.location != null)
                    shell.setLocation(event.location);

                if (event.size != null) {
                    Point size = event.size;
                    shell.setSize(shell.computeSize(size.x, size.y));
                }

                shell.open();
            }
        });


标签: java maven swt