yueguangm
发贴: 9
积分: 0
|
于 2004-10-09 17:39
是关于control控件中的tree的,我需要为树的节点添加listener。 参照例子做, final Tree tree = new Tree(shell, SWT.MULTI | SWT.BORDER); tree.setSize(150, 150); tree.setLocation(5,5);
TreeItem myComp = new TreeItem(tree, SWT.NONE); myComp.setText("My Computer"); TreeItem netPlaces = new TreeItem(tree, SWT.NONE); netPlaces.setText("My Network Places"); TreeItem myDocs = new TreeItem(tree, SWT.NONE, 1); myDocs.setText("My Documents");
TreeItem hardDisk = new TreeItem(myComp, SWT.NONE); hardDisk.setText("Local Disk (C"); TreeItem floppy = new TreeItem(myComp, SWT.NONE, 0); floppy.setText("3.5 Floppy (A"); TreeItem hardDisk = new TreeItem(myComp, SWT.NONE); hardDisk.setText("Local Disk (C"); TreeItem progFiles = new TreeItem(hardDisk, SWT.NONE); progFiles.setText("Program Files");
tree.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { TreeItem[] t = tree.getSelection(); System.out.print("Selection: "); for(int i = 0; i < t.length; i++) { System.out.print(t[i].getText() + ", "); } System.out.println(); } });
然而当我点击任一节点时,并没有出来我想要的Selection:...结果程序也不报错也没反应。不知道是什么问题? 请高手指教!
|