Pregunta

We have a Java application showing an embedded web page. It is done with NativeSwing jwebbrowser, but the embedded browser turns out to be IE7, so we are having issues with styles. That machine has IE8 installed, so I hoped it to be the default browser.

Is this a limitation of the library? Is there a way to select the browser version?

Thanks.

¿Fue útil?

Solución

After some hours work, I managed to run the jwebbrowser with the latest version of Internet Explorer installed on the system ( IE9 for me ).

The issue is related with the SWT version and described in the The SWT FAQ. For me including the swt.jar from this link and DJNativeSwing.jar and DJNativeSwing-SWT.jar from this link and running the following code

/*
 * 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();
      }
 }     

ends up showing:

You are using Internet Explorer Basic Info Browser Name: Internet Explorer Browser Version: 9.0 Your Platform: Windows ... (You may need to refresh once or twice to avoid caching)

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top