SWT JFACE 开发配制
所以即使你导入了org.eclipse.core.runtime_x.x.x.jar 到project也可能无济于事。
去plugins下面找找org.eclipse.equinox.common.x.x.x.jar,然后导入到project ,你会发现IProgressMonitor 悠然的躺在那里。
因为SWT使用了JNI调用C,所以你需要把相对应版本的dll文件(swt-win32-xxxx.dll)copy到C:/windows/system32下面.
解决了上面两个问题以为大功告成,其实还差一步。导入org.eclipse.core.commandsx.x.x.jar到project中,我们的第一个SWT/JFace就能跑起来了。
要导入的JAR:
D:\J2EE\eclipse-rcp-3.6\eclipse\plugins\org.eclipse.swt.win32.win32.x86_3.6.0.v3650b.jar
D:\J2EE\eclipse-rcp-3.6\eclipse\plugins\org.eclipse.jface_3.6.0.I20100601-0800.jar
D:\J2EE\eclipse-rcp-3.6\eclipse\plugins\org.eclipse.core.runtime_3.6.0.v20100505.jar
D:\J2EE\eclipse-rcp-3.6\eclipse\plugins\org.eclipse.ui.workbench_3.6.0.I20100603-1100.jar
D:\J2EE\eclipse-rcp-3.6\eclipse\plugins\org.eclipse.equinox.common_3.6.0.v20100503.jar
D:\J2EE\eclipse-rcp-3.6\eclipse\plugins\org.eclipse.equinox.event_1.2.0.v20100503.jar
D:\J2EE\eclipse-rcp-3.6\eclipse\plugins\org.eclipse.core.commands_3.6.0.I20100512-1500.jar
代码:
package com.swtjface.test;
import org.eclipse.jface.window.*;
import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;
public class HelloSWTJFace extends ApplicationWindow {
public static void main(String[] args) {
HelloSWTJFace awin = new HelloSWTJFace();
awin.setBlockOnOpen(true);
awin.open();
Display.getCurrent().dispose();
}
public HelloSWTJFace() {
super(null);
}
protected Control createContents(Composite parent) {
Text helloText = new Text(parent, SWT.CENTER);
helloText.setText("Hello SWT and JFace!");
parent.pack();
return parent;
}
}
package com.swtjface.test;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
public class HelloSwt {
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
Text helloText = new Text(shell, SWT.NONE);
helloText.setText("Hello SWT!");
helloText.pack();
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}