2、到https://github.com/Chrriis网站下载DJNativeSwing-SWT.zip或者DJNativeSwing.zip并解压。
3、copy网上的一段demo,测试。需要引入插件包DJNativeSwing-SWT.jar和DJNativeSwing.jar
运行,居然出错。
出错内容:Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/swt/SWT
http://ishare.iask.sina.com.cn/download/explain.php?fileid=20122660下载swt.jar包,并由eclipse引入。
运行,居然又出错。
出错内容:Exception in thread "main" java.lang.IllegalStateException: The version of SWT that is required is 3.7M5 or later!
at chrriis.dj.nativeswing.swtimpl.core.SWTNativeInterface.initialize_(SWTNativeInterface.java:209)
at chrriis.dj.nativeswing.swtimpl.NativeInterface.initialize(NativeInterface.java:71)
at chrriis.dj.nativeswing.swtimpl.core.SWTNativeInterface.open_(SWTNativeInterface.java:332)
at chrriis.dj.nativeswing.swtimpl.NativeInterface.open(NativeInterface.java:100)
at demo1.SimpleWebBrowserExample.main(SimpleWebBrowserExample.java:54)
之后再网上搜索,找到http://sourceforge.net/p/djproject/discussion/671154/thread/31b6ec57这个问题及回答。
里面有DJNativeSwing的原提供者的回答。
根据他的回答,意思是引入的swt包要3.7M5及以上的版本。
4、故,到http://www.java2s.com/Code/Jar/s/swt.htm该网址上有不同版本,不同系统的swt包,
在该网址上下载了3.7M7的swt.jar包,并引入到eclipse中。
5、运行该程序。binggo。成功。
结果截图如下:
附上源代码:
package demo1;
/*
* Christopher Deckers ()
* 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.
*/
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.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 extends JPanel {
public SimpleWebBrowserExample() {
super(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.google.com");
webBrowserPanel.add(webBrowser, BorderLayout.CENTER);
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);
add(buttonPanel, BorderLayout.SOUTH);
}
/* Standard main method to try that test as a standalone application. */
public static void main(String[] args) {
UIUtils.setPreferredLookAndFeel();
NativeInterface.open();
SwingUtilities.invokeLater(new Runnable() {
public void run() {
JFrame frame = new JFrame("DJ Native Swing Test");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(new SimpleWebBrowserExample(), BorderLayout.CENTER);
frame.setSize(800, 600);
frame.setLocationByPlatform(true);
frame.setVisible(true);
}
});
NativeInterface.runEventPump();
}
}
注:本文所用到的源代码并不是由本人所写。本文章旨在帮忙解决初学内嵌者跟我一样遇到的问题。