java swing内嵌浏览器

DJNativeSwing

它是native code实现的,但是集成在java swing代码中也没有任何问题。网址是:Native Swing

不只是浏览器,还有vlc,flash等等,包括例子官方也很丰富。

当然默认只有win32的,不过也不要灰心,DJNativeSwing是基于swt,所以只要下载对应操作系统的swt.jar就可以了。

我的是linux 64bit 下载对应的swt.jar。一样可以运行,对于swt.jar. google一下就可以找到。

希望对你们有所帮助。

 

附上官网代码

  1. /*
  2.  * Christopher Deckers (chrriis@nextencia.net)
  3.  * http://www.nextencia.net
  4.  *
  5.  * See the file "readme.txt" for information on usage and redistribution of
  6.  * this file, and for a DISCLAIMER OF ALL WARRANTIES.
  7.  */
  8. package chrriis.dj.nativeswing.swtimpl.demo.examples.webbrowser;
  9. import java.awt.BorderLayout;
  10. import java.awt.FlowLayout;
  11. import java.awt.event.ItemEvent;
  12. import java.awt.event.ItemListener;
  13. import javax.swing.BorderFactory;
  14. import javax.swing.JCheckBox;
  15. import javax.swing.JFrame;
  16. import javax.swing.JPanel;
  17. import javax.swing.SwingUtilities;
  18. import chrriis.common.UIUtils;
  19. import chrriis.dj.nativeswing.swtimpl.NativeInterface;
  20. import chrriis.dj.nativeswing.swtimpl.components.JWebBrowser;
  21. /**
  22.  * @author Christopher Deckers
  23.  */
  24. public class SimpleWebBrowserExample extends JPanel {
  25.   public SimpleWebBrowserExample() {
  26.     super(new BorderLayout());
  27.     JPanel webBrowserPanel = new JPanel(new BorderLayout());
  28.     webBrowserPanel.setBorder(BorderFactory.createTitledBorder("Native Web Browser component"));
  29.     final JWebBrowser webBrowser = new JWebBrowser();
  30.     webBrowser.navigate("http://www.google.com");
  31.     webBrowserPanel.add(webBrowser, BorderLayout.CENTER);
  32.     add(webBrowserPanel, BorderLayout.CENTER);
  33.     // Create an additional bar allowing to show/hide the menu bar of the web browser.
  34.     JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 4, 4));
  35.     JCheckBox menuBarCheckBox = new JCheckBox("Menu Bar", webBrowser.isMenuBarVisible());
  36.     menuBarCheckBox.addItemListener(new ItemListener() {
  37.       public void itemStateChanged(ItemEvent e) {
  38.         webBrowser.setMenuBarVisible(e.getStateChange() == ItemEvent.SELECTED);
  39.       }
  40.     });
  41.     buttonPanel.add(menuBarCheckBox);
  42.     add(buttonPanel, BorderLayout.SOUTH);
  43.   }
  44.   /* Standard main method to try that test as a standalone application. */
  45.   public static void main(String[] args) {
  46.     UIUtils.setPreferredLookAndFeel();
  47.     NativeInterface.open();
  48.     SwingUtilities.invokeLater(new Runnable() {
  49.       public void run() {
  50.         JFrame frame = new JFrame("DJ Native Swing Test");
  51.         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  52.         frame.getContentPane().add(new SimpleWebBrowserExample(), BorderLayout.CENTER);
  53.         frame.setSize(800, 600);
  54.         frame.setLocationByPlatform(true);
  55.         frame.setVisible(true);
  56.       }
  57.     });
  58.     NativeInterface.runEventPump();
  59.   }
  60. }
  1. da shang
    donate-alipay
               donate-weixin weixinpay

发表评论↓↓