[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[news.eclipse.platform.swt] Re: Method that bring location of TreeItem in Tree?

I'm not sure what you mean by "location" (in the tree?  x,y?). 
Regardless, with a TreeListener you can get the collapsed TreeItem
directly.  Snippet:

	public static void main(String[] args) {
		Display display = new Display();
		Shell shell = new Shell(display);
		shell.setBounds(10,10,300,300);
		
		Tree tree = new Tree(shell,SWT.NONE);
		tree.setBounds(10,10,200,200);
		TreeItem[] items = new TreeItem[9];
		items[0] = new TreeItem(tree,SWT.NONE);
		items[0].setText("item 0");
		for (int i = 1; i < 9; i++) {
			items[i] = new TreeItem(items[i-1], SWT.NONE);
			items[i].setText("item " + i);
		}
		tree.addTreeListener(new TreeListener() {
			public void treeCollapsed(TreeEvent arg0) {
				TreeItem item = (TreeItem)arg0.item;
				System.out.println("collapsed " + item.getText() + "[" +
item.getBounds() + "]");
			}
			public void treeExpanded(TreeEvent arg0) {}
		});
		
		shell.open();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) display.sleep();
		}
		display.dispose();
	}

Grant


yoonng wrote:


> When TreeItem has been collapsed, need ParentTreeItem's location.

> What method is?