How to create a JTree with multiple root node?

Discussion in 'Java' started by Allen, Jul 12, 2006.

  1. Allen

    Allen Guest

    I want to create a tree like eclipse package explorer. Who can tell me
    how to cope with root node? Thank you.
     
    Allen, Jul 12, 2006
    #1
    1. Advertising

  2. Allen wrote:
    > 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.
     
    Brandon McCombs, Jul 12, 2006
    #2
    1. Advertising

  3. Allen

    Rogan Dawes Guest

    Brandon McCombs wrote:
    > Allen wrote:
    >> 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.


    tree.setRootNodeVisible(false);

    Then only your second level (and deeper) nodes are visible, and it looks
    like you have a multi-rooted tree.

    Rogan
     
    Rogan Dawes, Jul 12, 2006
    #3
  4. Allen

    Chris Smith Guest

    Allen <> wrote:
    > 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.

    --
    Chris Smith - Lead Software Developer / Technical Trainer
    MindIQ Corporation
     
    Chris Smith, Jul 12, 2006
    #4
  5. Allen

    Allen Guest

    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");
     
    Allen, Jul 14, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    1,470
  2. Tjerk Wolterink
    Replies:
    2
    Views:
    1,440
    Dimitre Novatchev
    Aug 24, 2006
  3. Jason Cavett

    How to Get Root Path in JTree

    Jason Cavett, Feb 7, 2007, in forum: Java
    Replies:
    2
    Views:
    3,404
    Jason Cavett
    Feb 8, 2007
  4. Replies:
    1
    Views:
    566
    Martin Honnen
    May 8, 2007
  5. jumpz
    Replies:
    3
    Views:
    627
    Jean-Baptiste Nizet
    Nov 12, 2007
Loading...

Share This Page