首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >需要Jwebbrowser才能使用最新的浏览器

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

Stack Overflow用户
提问于 2012-10-26 16:20:59
回答 1查看 6.9K关注 0票数 2

我们有一个显示嵌入式网页的Java应用程序。这是用NativeSwing jwebbrowser完成的,但是嵌入式浏览器是IE7,所以我们在样式方面有问题。那台机器安装了IE8,所以我希望它是默认的浏览器。

这是库的限制吗?有没有办法选择浏览器版本?

谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-11-11 02:07:42

经过几个小时的工作,我设法在系统上安装了最新版本的Internet Explorer (对于我来说是IE9 )来运行jwebbrowser。

该问题与SWT版本相关,并在The SWT FAQ中进行了描述。对于我来说,包括来自this link和DJNativeSwing.jar的swt.jar以及来自this link的DJNativeSwing-SWT.jar,并运行以下代码

代码语言:javascript
复制
/*
 * 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();
      }
 }     

最终显示:

您正在使用Internet Explorer基本信息浏览器名称: Internet Explorer浏览器版本: 9.0您的平台:Windows...(您可能需要刷新一次或两次以避免缓存)

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13083290

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档