| [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:
|