我们有一个显示嵌入式网页的 Java 应用程序。 它是用 NativeSwing jwebbrowser 完成的,但嵌入式浏览器原来是 IE7,所以我们遇到了样式问题。 那台机器安装了IE8,所以我希望它成为默认浏览器。
这是图书馆的限制吗?有没有办法选择浏览器版本?
谢谢。
最佳答案
经过几个小时的工作,我成功地在系统上安装了最新版本的 Internet Explorer(对我来说是 IE9)来运行 jwebbrowser。
该问题与 SWT 版本相关,并在 The SWT FAQ 中进行了描述。 。 对我来说包括来自 this link 的 swt.jar以及来自 this link 的 DJNativeSwing.jar 和 DJNativeSwing-SWT.jar并运行以下代码
/*
* Christopher Deckers (<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="55363d27273c3c26153b302d21303b363c347b3b3021" rel="noreferrer noopener nofollow">[email protected]</a>)
* http://www.nextencia.net
*
* See the file "readme.txt" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*/
package chrriis.dj.nativeswing.swtimpl.demo.examples.webbrowser;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.BorderFactory;
import javax.swing.JCheckBox;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import chrriis.common.UIUtils;
import chrriis.dj.nativeswing.swtimpl.NativeInterface;
import chrriis.dj.nativeswing.swtimpl.components.JWebBrowser;
/**
* @author Christopher Deckers
*/
public class SimpleWebBrowserExample {
public static JComponent createContent() {
JPanel contentPane = new JPanel(new BorderLayout());
JPanel webBrowserPanel = new JPanel(new BorderLayout());
webBrowserPanel.setBorder(BorderFactory.createTitledBorder("Native Web Browser component"));
final JWebBrowser webBrowser = new JWebBrowser();
webBrowser.navigate("http://www.browserproperties.com");
webBrowserPanel.add(webBrowser, BorderLayout.CENTER);
contentPane.add(webBrowserPanel, BorderLayout.CENTER);
// Create an additional bar allowing to show/hide the menu bar of the web browser.
JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 4, 4));
JCheckBox menuBarCheckBox = new JCheckBox("Menu Bar", webBrowser.isMenuBarVisible());
menuBarCheckBox.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
webBrowser.setMenuBarVisible(e.getStateChange() == ItemEvent.SELECTED);
}
});
buttonPanel.add(menuBarCheckBox);
contentPane.add(buttonPanel, BorderLayout.SOUTH);
return contentPane;
}
/* Standard main method to try that test as a standalone application. */
public static void main(String[] args) {
NativeInterface.open();
UIUtils.setPreferredLookAndFeel();
SwingUtilities.invokeLater(new Runnable() {
public void run() {
JFrame frame = new JFrame("DJ Native Swing Test");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(createContent(), BorderLayout.CENTER);
frame.setSize(800, 600);
frame.setLocationByPlatform(true);
frame.setVisible(true);
}
});
NativeInterface.runEventPump();
}
}
最终显示:
您正在使用 IE浏览器 基本信息 浏览器名称:Internet Explorer 浏览器版本:9.0 您的平台:Windows ... (您可能需要刷新一两次以避免缓存)
关于java - 需要Jwebbrowser才能使用最新的浏览器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13083290/