博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
java内嵌浏览器DJNativeSwing
阅读量:6911 次
发布时间:2019-06-27

本文共 2115 字,大约阅读时间需要 7 分钟。

hot3.png

 

由于一个项目的需要,必须在程序中嵌入一个浏览器来完成用户的一些操作,研究了几天之后本人决定使用DJ NativeSwing这个控件,该空间需要使用以下jar包支持 
1.DJNativeSwing.jar 
2.DJNativeSwing-SWT.jar 
3.org.eclipse.swt.win32.win32.x86_64_3.100.1.v4236b.jar 或者 org.eclipse.swt.win32.win32.x86_3.102.0.v20130605-1544 
下载地址(免积分下载):http://download.csdn.net/detail/shikai2008/6344335 
其中前两个为必须jar包,第三个根据操作系统选择自己合适的jar包即可。 
前期工作做好之后就可以编写自己的代码了。 

Java代码 

 收藏代码

  1. import java.awt.BorderLayout;    
  2.     
  3. import javax.swing.JFrame;    
  4. import javax.swing.JPanel;    
  5. import javax.swing.SwingUtilities;    
  6.     
  7. import chrriis.common.UIUtils;    
  8. import chrriis.dj.nativeswing.swtimpl.NativeInterface;    
  9. import chrriis.dj.nativeswing.swtimpl.components.JWebBrowser;    
  10. import chrriis.dj.nativeswing.swtimpl.components.WebBrowserAdapter;    
  11. import chrriis.dj.nativeswing.swtimpl.components.WebBrowserEvent;    
  12.     
  13. public class Test extends JPanel {    
  14.     
  15.     private static final long serialVersionUID = 1L;    
  16.     
  17.     private JPanel webBrowserPanel;    
  18.     
  19.     private JWebBrowser webBrowser;    
  20.     
  21.     // private String url;    
  22.     
  23.     public Test(String url) {    
  24.         super(new BorderLayout());    
  25.         this.url = url;    
  26.         webBrowserPanel = new JPanel(new BorderLayout());    
  27.         webBrowser = new JWebBrowser();    
  28.         webBrowser.navigate(url);    
  29.         webBrowser.setButtonBarVisible(false);    
  30.         webBrowser.setMenuBarVisible(false);    
  31.         webBrowser.setBarsVisible(false);    
  32.         webBrowser.setStatusBarVisible(false);    
  33.         webBrowserPanel.add(webBrowser, BorderLayout.CENTER);    
  34.         add(webBrowserPanel, BorderLayout.CENTER);    
  35.         // webBrowser.executeJavascript("javascrpit:window.location.href='http://www.baidu.com'");    
  36.          webBrowser.executeJavascript("alert('haha')"); //执行Js代码    
  37.     }    
  38.     
  39.     public static void main(String[] args) {    
  40.         final String url = "http://www.baidu.com";    
  41.         final String title = "DJ NativeSwiting Test";    
  42.         UIUtils.setPreferredLookAndFeel();    
  43.         NativeInterface.open();    
  44.     
  45.         SwingUtilities.invokeLater(new Runnable() {    
  46.             public void run() {    
  47.                 JFrame frame = new JFrame(title);    
  48.                 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);    
  49.                 frame.getContentPane().add(new Test(url), BorderLayout.CENTER);    
  50.                 frame.setExtendedState(JFrame.MAXIMIZED_BOTH);    
  51.                 frame.setLocationByPlatform(true);    
  52.                 frame.setVisible(true);    
  53.             }    
  54.         });    
  55.         NativeInterface.runEventPump();    
  56.     }    
  57.     
  58. }    

SouthEast

转载于:https://my.oschina.net/xiaominmin/blog/1828845

你可能感兴趣的文章
setInterval() 方法应用
查看>>
WPF(命令参数)
查看>>
iOS MVVM 前世今生
查看>>
tomcat 安全文件夹(Java之负基础实战)
查看>>
IO---Java 文件复制
查看>>
BeanShell用法(摘抄至网络)
查看>>
Monkey工具使用详解
查看>>
knockout 你想知道的常用功能
查看>>
MySQL入门01-MySQL源码安装
查看>>
CentOS 7 安装 Oracle 11g
查看>>
sqlmap注入工具----一次简单的注入(实战)
查看>>
腾讯云部署
查看>>
MySql详解(七)
查看>>
POJ3984 迷宫问题
查看>>
POJ2785:4 Values whose Sum is 0(二分+暴力)
查看>>
interface -- 接口类
查看>>
可怜的小老鼠分析
查看>>
关于设计的一些想法
查看>>
seacms最新版前台getshell
查看>>
linux内核启动笔记
查看>>