Tree的小例子(3级树)

例子来源:http://www.eclipse.org/swt/snippets

 

在org.eclipse.swt.widgets.Tree的javadoc中可以看,Tree可以支持的类型和事件,TreeItem没有什么类型和事件,这样对于一个特定的Item的事件就要加到Tree上面,后分辨不同的Item来处理了。

Styles:
SINGLE, MULTI, CHECK, FULL_SELECTION, VIRTUAL, NO_SCROLL
Events:
Selection, DefaultSelection, Collapse, Expand, SetData, MeasureItem, EraseItem, PaintItem,MouseDown

Snippet15

 

public class Snippet15 {
	public static void main (String [] args) {
		final Display display = new Display ();
		final Shell shell = new Shell (display);
		shell.setLayout(new FillLayout());
		final Tree tree = new Tree (shell, SWT.BORDER);
		TreeItem iItem, jItem, kItem;
		for (int i=0; i<3; i++) {
			iItem = new TreeItem (tree, 0);
			iItem.setText ("TreeItem (0) -" + i);
			for (int j=0; j<3; j++) {
				jItem = new TreeItem (iItem, 0);
				jItem.setText ("TreeItem (1) -" + j);
				for (int k=0; k<3; k++) {
					kItem = new TreeItem (jItem, 0);
					kItem.setText ("TreeItem (2) -" + k);
				}
			}
		}
		shell.setSize (200, 200);
		shell.open ();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch ()) display.sleep ();
		}
		display.dispose ();
	}
} 

 

 

一个3级的树。



 

一般情况下Tree在有些数据没有办法现象的情况下是有滚动条的,也可以强制关闭滚动条,如下:

public class Snippet302 {
	public static void main (String [] args) {
		Display display = new Display ();
		Shell shell = new Shell (display);
		FillLayout layout = new FillLayout();
		layout.marginHeight = 10;
		layout.marginWidth = 10;
		shell.setLayout(layout);
		Tree tree = new Tree (shell, SWT.BORDER | SWT.NO_SCROLL);
		for (int i=0; i<10; i++) {
			TreeItem item = new TreeItem (tree, SWT.NONE);
			item.setText ("Item " + i);
		}
		shell.pack ();
		shell.open ();
		while (!shell.isDisposed ()) {
			if (!display.readAndDispatch ()) display.sleep ();
		}
		display.dispose ();
	}
}

 



 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值