|
Re: clear tree selection [message #504420 is a reply to message #504199] |
Fri, 18 December 2009 19:46 |
Grant Gayed Messages: 2150 Registered: July 2009 |
Senior Member |
|
|
Hi,
This should work, and it works for me with the snippet below (tried Windows
2000). Does the snippet work for you? And if so, are you able to change it
to resemble your case and to show the problem? And which platform are you
using?
public static void main(String[] args) {
final Display display = new Display();
Shell shell = new Shell(display);
shell.setBounds(200, 200, 400, 400);
shell.setLayout(new FillLayout());
final Tree tree = new Tree(shell, SWT.MULTI);
for (int i = 0; i < 9; i++) {
new TreeItem(tree, SWT.NONE).setText("item " + i);
}
shell.open();
tree.addListener(SWT.MouseUp, new Listener() {
public void handleEvent(Event event) {
TreeItem item = tree.getItem(new Point(event.x, event.y));
if (item == null) {
tree.setSelection(new TreeItem[] {});
}
System.out.println("selection length: " +
tree.getSelection().length);
}
});
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) display.sleep();
}
shell.dispose();
display.dispose();
}
Grant
"Domitian Tamas-Selicean" <domihq@gmail.com> wrote in message
news:hgdm0u$im8$1@build.eclipse.org...
> Hello all,
>
> I've been trying to find a solution for my problem, but it looks like
either google ain't my friend or there ain't any.
>
> Is there a way I can clear the tree selection? For example I have a
multiple selection tree. I added a mouse listener to the tree, and if the
mouse up event occurs not on top of a treeItem, I want to clear the previous
selection.
>
> I tried setting the selection using an empty TreeItem array, but it has
only a visual effect. The tree#getSelection() call will return the
previously selected items.
>
> Any solutions are welcomed.
> Thanks,
>
> D
|
|
|
Powered by
FUDForum. Page generated in 0.03595 seconds