gpt4 book ai didi

java - 需要Jwebbrowser才能使用最新的浏览器

转载 作者:行者123 更新时间:2023-11-30 09:30:54 24 4
gpt4 key购买 nike

我们有一个显示嵌入式网页的 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 (chrriis@nextencia.net)
* 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com