Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Select first node in tree?
Select first node in tree? [message #466070] Fri, 30 December 2005 19:14 Go to next message
mp is currently offline mpFriend
Messages: 8
Registered: July 2009
Junior Member
What is the quickest way to select the first node in a tree?

Should a lookup be done on text or can it be done differently..
Re: Select first node in tree? [message #466072 is a reply to message #466070] Fri, 30 December 2005 19:36 Go to previous messageGo to next message
mp is currently offline mpFriend
Messages: 8
Registered: July 2009
Junior Member
Hmm had to look better. This is my own solution. If it can be done better
let me know.

private void selectFirstRootItem() {
TreeItem[] sel = new TreeItem[1];
if (tree.getItemCount() > 0) {
sel[0] = tree.getItems()[0];
tree.setSelection(sel);
tree.showSelection();
}
}
Re: Select first node in tree? [message #466110 is a reply to message #466072] Mon, 02 January 2006 15:11 Go to previous messageGo to next message
Daniel Spiewak is currently offline Daniel SpiewakFriend
Messages: 263
Registered: July 2009
Senior Member
That's the solution that I've been using. I don't that there's a more elegant way of doing it (not that our way is terribly ugly, but you know what I mean).
Re: Select first node in tree? [message #466146 is a reply to message #466072] Tue, 03 January 2006 19:39 Go to previous messageGo to next message
Veronika Irvine is currently offline Veronika IrvineFriend
Messages: 1272
Registered: July 2009
Senior Member
if (tree.getItemCount() > 0) {
tree.setSelection(new TreeItem[]{tree.getItem(0)});
}

Note: tree.showSelection(); is not neccessary as this is part of
setSelection()
Getting one item at an index is much more effecient than getting all the
items.

"mp" <pijnmar@home.nl> wrote in message
news:ab29dad5d574d5c974e7e7104a57ce24$1@www.eclipse.org...
> Hmm had to look better. This is my own solution. If it can be done better
> let me know.
>
> private void selectFirstRootItem() {
> TreeItem[] sel = new TreeItem[1];
> if (tree.getItemCount() > 0) {
> sel[0] = tree.getItems()[0];
> tree.setSelection(sel);
> tree.showSelection();
> } }
>
Re: Select first node in tree? [message #466171 is a reply to message #466146] Wed, 04 January 2006 13:34 Go to previous messageGo to next message
mp is currently offline mpFriend
Messages: 8
Registered: July 2009
Junior Member
thank you!
Re: Select first node in tree? [message #466199 is a reply to message #466146] Wed, 04 January 2006 19:18 Go to previous message
Daniel Spiewak is currently offline Daniel SpiewakFriend
Messages: 263
Registered: July 2009
Senior Member
<i>Getting one item at an index is much more effecient than getting all the items.</i>

<<slaps forehead>> Darn, I should have thought of that. :-) Thanks for the pointer.
Previous Topic:Selection Cell Colors for Two Tables???
Next Topic:AWT component into SWT image
Goto Forum:
  


Current Time: Wed Dec 04 15:50:11 GMT 2024

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

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

Back to the top