1

我在 Swing 应用程序中使用 JWebBrowser 作为组件。当我单击 JWebBrowser 中的链接时,它会打开一个新窗口(window.open() javascript),但由 Swing 组件包装。我希望它在 IE 浏览器中打开!JWebBrowser 是否有任何属性允许这样做?

4

1 回答 1

1

我有类似的问题,大部分代码取自原始示例: 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();
                    }
                });
            }
        });
    }
});
于 2013-07-20T07:03:05.940 回答