我使用了 Java 和 SWT 的浏览器
。我准备了两个系统版本的应用程序,第一个用于 OSX,第二个用于 Windows。
两个系统都是 64 位
SWT 需要针对不同系统的不同库,因此在 Maven 中我声明了两者
<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>
在浏览器中,我加载页面并单击按钮(创建新窗口),但我不想打开新窗口,只重新加载实际浏览器的新页面,我像下面的代码一样这样做
browser.addOpenWindowListener(new OpenWindowListener() {
public void open(WindowEvent event) {
Log.debug(TAG + "<>", "Open new page!");
event.browser = browser;
}
});
在 OS X 系统上它运行得很好。
但是当我在 Windows 上尝试时,单击按钮后旧页面不会更改。我检查了日志和消息“打开新页面!”已写入但没有任何反应(新页面不会像 OS X 中那样加载)。我虽然这可能是通过 WebKit 加载页面后刷新和 browser.refresh()
刷新浏览器,但有旧内容(不像 OS X 中的新内容)。
我调试并检查了 SWT 库中的 event.browser = browser;
WebKit 控制后发生的情况。
我应该怎样做才能在 Windows 上获得与 OS X 相同的效果?
最佳答案
已解决
问题出在库中。在 OSX 系统上,当我们更改 event.browser
对象时,会自动检测到并且它可以工作,但在 Windows 系统上,我们需要添加到浏览器 VisibilityWindowListener
,如下面的代码片段所示并且可以工作很好:)
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 - 不同系统上的 SWT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39832253/