我使用JWebBrowser作为Swing应用程序中的组件。当我单击JWebBrowser中的链接时,它会打开一个新窗口(window.open() javascript),但由Swing组件包装。我想在IE浏览器中打开它!是否有任何属性的JWebBrowser允许这一点?
我有类似的问题,大部分代码取自原始示例:http://djproject.cvs.sourceforge.net/viewvc/djproject/DJNativeSwing-SWTDemo/src/chrriis/dj/nativeswing/swtimpl/demo/examples/webbrowser/NavigationControl.java?pathrev=R-1_0_1
browser.addWebBrowserListener(new WebBrowserAdapter() {
public void windowWillOpen(WebBrowserWindowWillOpenEvent e) {
// get the new swing window
final JWebBrowser newBrowser = e.getNewWebBrowser();
newBrowser.addWebBrowserListener(new WebBrowserAdapter() {
@Override
public void locationChanging(WebBrowserNavigationEvent newEvent) {
// launch default OS browser
if (Desktop.isDesktopSupported()) {
Desktop desktop = Desktop.getDesktop();
if (desktop.isSupported(Desktop.Action.BROWSE)) {
try {
desktop.browse(new URI(newEvent.getNewResourceLocation()));
} catch (Exception ex) {}
}
}
newEvent.consume();
// immediately close the new swing window
SwingUtilities.invokeLater(new Runnable() {
public void run() {
newBrowser.getWebBrowserWindow().dispose();
}
});
}
});
}
});