这段代码可以你看看!/** *author jason */ package com.wzkj.test;import org.eclipse.swt.SWT; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Tree; import org.eclipse.swt.widgets.TreeItem;public class TreeSample { private Shell sShell = null; public TreeSample() { // TODO 自动生成构造函数存根 } /** * @param args */ public static void main(String[] args) { // TODO 自动生成方法存根 /* Before this is run, be sure to set up the launch configuration (Arguments->VM Arguments) * for the correct SWT library path in order to run with the SWT dlls. * The dlls are located in the SWT plugin jar. * For example, on Windows the Eclipse SWT 3.1 plugin jar is: * installation_directory\plugins\org.eclipse.swt.win32_3.1.0.jar */ Display display = Display.getDefault(); TreeSample thisClass = new TreeSample(); thisClass.createSShell(); thisClass.sShell.open(); while (!thisClass.sShell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); } /** * This method initializes sShell */ private void createSShell() { sShell = new Shell(); sShell.setText("Shell"); sShell.setSize(new Point(300, 200)); sShell.setLayout(new FillLayout());
Tree tree = new Tree(sShell, SWT.FULL_SELECTION); tree.setSize(200, 100); TreeItem root = new TreeItem(tree, SWT.NULL); root.setText("root");
for (int i = 0; i < 10; i++) { TreeItem item = new TreeItem(root, SWT.NULL); item.setText("Item"+i); } }}
*author jason
*/ package com.wzkj.test;import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;public class TreeSample { private Shell sShell = null; public TreeSample() {
// TODO 自动生成构造函数存根
} /**
* @param args
*/
public static void main(String[] args) {
// TODO 自动生成方法存根
/* Before this is run, be sure to set up the launch configuration (Arguments->VM Arguments)
* for the correct SWT library path in order to run with the SWT dlls.
* The dlls are located in the SWT plugin jar.
* For example, on Windows the Eclipse SWT 3.1 plugin jar is:
* installation_directory\plugins\org.eclipse.swt.win32_3.1.0.jar
*/
Display display = Display.getDefault();
TreeSample thisClass = new TreeSample();
thisClass.createSShell();
thisClass.sShell.open();
while (!thisClass.sShell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
} /**
* This method initializes sShell
*/
private void createSShell() {
sShell = new Shell();
sShell.setText("Shell");
sShell.setSize(new Point(300, 200));
sShell.setLayout(new FillLayout());
Tree tree = new Tree(sShell, SWT.FULL_SELECTION);
tree.setSize(200, 100);
TreeItem root = new TreeItem(tree, SWT.NULL);
root.setText("root");
for (int i = 0; i < 10; i++) {
TreeItem item = new TreeItem(root, SWT.NULL);
item.setText("Item"+i);
}
}}