Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4040454
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T12:45:19+00:00 2026-05-20T12:45:19+00:00

I have a single node that has all the child nodes and attributes in

  • 0

I have a single node that has all the child nodes and attributes in the following format.

node =   Root[
         attributes = {rootattribute1, rootattribute2,...}, 
         value = [100,
                childNode1
                [
                attributes = {childNode2att1,.....}
                value = [1001]  
                ]

                childNode2
                [
                attributes = {childNode2attributes,.....}
                value = [1001]  
                ] ......... and some other childnodes like this
                ]

When I use Jtree tree = new Jtree(node); It is creating just a single rootelement for the tree showing all these details within a single row of a tree.

Instead I want to display the tree in the correct hierarchy with nested child nodes and atrribute values. Is there any inbuilt method to do this ?

If there is no inbuilt method to do this how do I write the code for this ?

PS: the node content displayed above is dynamic and is not static.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T12:45:19+00:00Added an answer on May 20, 2026 at 12:45 pm

    You can start with something like:

    import javax.swing.*
    import javax.swing.tree.*
    
    class Root {
        def attributes = []
        def children = []
        def value = 0
    
        def String toString() { 
            "[${value}] attributes: ${attributes} children: ${children}" 
        }
    }
    
    def createTreeNode(node) {
        def top = new DefaultMutableTreeNode(node.value)
        for (attr in node.attributes) {
            top.add(new DefaultMutableTreeNode(attr))
        }
        for (child in node.children) {
            top.add(createTreeNode(child))
        }   
        top
    }
    
    root = new Root(
        attributes: ['rootattribute1', 'rootattribute2'], 
        value: 100,
        children: [
            new Root(
                attributes: ['childNode2att1'],
                value: 1001),
            new Root(
                attributes: ['childNode2attributes'],
                value: 1002),    
        ])
    
    
    frame = new JFrame('Tree Test')
    frame.setSize(300, 300)
    frame.defaultCloseOperation = JFrame.EXIT_ON_CLOSE
    jtree = new JTree(createTreeNode(root))
    frame.add(jtree)
    frame.show()
    

    JTree is a sophisticated component – please read the JTree Swing Tutorial for more details on how to customize the tree for your exact needs.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an XML document that has nodes like the following: <objects> <dog> <data1>...</data1>
I have a content type (A) that references a single node of a different
I have an single threaded, embedded application that allocates and deallocates lots and lots
I have a single user java program that I would like to have store
I have a single line CEikLabel in my application that needs to scroll text.
I have a single spool mbox file that was created with evolution, containing a
I have a single Rails 2.2.2 app that I want to 'share' with multiple
We have a Single Statement FUNCTION in SQL Server 2005 which uses CONTAINSTABLE(). All
I have a single RoutedUICommand that can be accessed through various places in the
I have a hierarchical generic data structure. There is a root node and under

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.