Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / July 2006

Tip: Looking for answers? Try searching our database.

How to create a JTree with multiple root node?

Thread view: 
Allen - 12 Jul 2006 03:21 GMT
I want to create a tree like eclipse package explorer. Who can tell me
how to cope with root node? Thank you.
Brandon McCombs - 12 Jul 2006 06:20 GMT
> 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
Chris Smith - 12 Jul 2006 23:03 GMT
> 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");


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.