Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » clear tree selection(Is it possible to clear the SWT tree selection?)
clear tree selection [message #504199] Thu, 17 December 2009 16:25 Go to next message
Tamas-Selicean Domitian is currently offline Tamas-Selicean DomitianFriend
Messages: 10
Registered: July 2009
Junior Member
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
Re: clear tree selection [message #504420 is a reply to message #504199] Fri, 18 December 2009 19:46 Go to previous message
Grant Gayed is currently offline Grant GayedFriend
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
Previous Topic:More strange Cocoa behavior
Next Topic:DND files from KDE based app to swt app?
Goto Forum:
  


Current Time: Sat Apr 27 02:17:15 GMT 2024

Powered by FUDForum. Page generated in 0.03595 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top