I want to create a tree like eclipse package explorer. Who can tell me
how to cope with root node? Thank you.
> I want to create a tree like eclipse package explorer. Who can tell me
> how to cope with root node? Thank you.
I can't say for sure (someone else can confirm) but from what I can tell
it looks like they have a single invisible root and any project/package
that you have defined in that view is just considered a 2nd level node
in the tree but the key is that the root itself is invisible so it just
gives the appearance that the others are at the root.
Rogan Dawes - 12 Jul 2006 06:53 GMT
>> I want to create a tree like eclipse package explorer. Who can tell me
>> how to cope with root node? Thank you.
[quoted text clipped - 4 lines]
> in the tree but the key is that the root itself is invisible so it just
> gives the appearance that the others are at the root.
tree.setRootNodeVisible(false);
Then only your second level (and deeper) nodes are visible, and it looks
like you have a multi-rooted tree.
Rogan
> I want to create a tree like eclipse package explorer. Who can tell me
> how to cope with root node? Thank you.
In SWT, or in Swing?
SWT: If using JFace (which I'd strongly recommend), then you have an
implementation of ITreeContentProvider, which extends
IStructuredContentProvider. You will implement getElements from the
latter class. Simply return all the top-level items as elements:
Swing: Swing's JTree must have a single root, but you can configure the
tree not to show it. Call setRootVisible(false) on the JTree object.

Signature
Chris Smith - Lead Software Developer / Technical Trainer
MindIQ Corporation
Allen - 14 Jul 2006 01:54 GMT
Thank you!
Yes, I call javax.swing.JTree setRootVisible(false) to hide the root
node.
But there comes another question. The first level, i.e. multiple roots
level, has not angled
line, while the other levels have. It is uneasy to differ from root
nodes from root child nodes on the UI. So how to show angled line for
root nodes?
putClientProperty("JTree.lineStyle", "Angled");