[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[news.eclipse.platform.swt] Re: Invisible root TreeItem?

You don't cast anything to anything.  Nor does SWT create a default root item for you.  What you do is as follows:

    ...
    Tree tree = new Tree(parent, SWT.BORDER | SWT.SINGLE | SWT.FULL_SELECTION);

    TreeItem root1 = new TreeItem(tree, SWT.NONE);
    root1.setText("This is the first root item");

    TreeItem root2 = new TreeItem(tree, SWT.NONE);
    root2.setText("This is the second root item");

    TreeItem child1 = new TreeItem(root2, SWT.NONE);
    child1.setText("This item is the first child item");
    ...

This code will create a tree structure as follows:

    | - This is the first root item
    | - This is the second root item
         | - This is the first child item

As you see, there are litterally two root items, not one invisible root item.  This simplifies things conceptually and saves on memory.  As to the overloaded constructors for TreeItem, I suggest that you do as I do when I work with Tree(s): create a method to add a TreeItem to a Tree based on data passed to it, and then overload the method for adding a TreeItem to another TreeItem.  You can litterally cut and paste your code from one method to the other as long as you keep your parameter names straight.

Daniel

Joel Chen wrote:
I am not sure what you mean, but I am not that good with SWT and a bit rusty with Java itself, however I see no remedy to my situation from what you said.  The fact that there are two ways I can create a TreeItem like:
 
new TreeItem( Tree, style )
or
new TreeItem( TreeItem, style )
 
and that you can't cast Tree to TreeItem is kind of clunky and I have to have two versions of some of my code to deal with it. 
 
If Tree creates a default root item that's invisible, then I don't have this problem.  Even then, you can still have multiple "root" items under the default root item, right?
 
I am sure I am missing something here since no one seem to complain about this, but I see no clear way around it.
 
 
"Daniel Spiewak" <djspiewak@xxxxxxxxxx> wrote in message news:d78hll$1rl$1@xxxxxxxxxxxxxxxx...
You can create multiple root tree items on the Tree itself.  Unlike with Swing, you can have more than one root.  Thus, accomplishing in actuality what Swing accomplishes by illusion.

Daniel

Joel Chen wrote:
Is is possible to create a TreeItem that's invisble to serve as the root 
item?  I found myself end up with a bunch of functions with identical body 
but one takes Tree and another takes TreeItem in its parameters.  I could 
get around this by just creating a rootTreeItem but now I lost some space in 
the left margin in my tree display.