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

  • SEARCH
  • Home
  • 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 8322039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T23:14:22+00:00 2026-06-08T23:14:22+00:00

I have a list populated with duplicate entries. I am using a hash to

  • 0

I have a list populated with duplicate entries. I am using a hash to store each unique entry from this list. Each key will then point to an object of type DefaultMutableTreeNode which represents the JTree node. My goal is to have this node point to all entries from the list which have the same node-same as the parent.

I have added these parent-nodes without problems but when the children nodes are added (via insertNodeInto), only parent nodes appear. A code-snippet is below; am very appreciative for advice / time.

// an unsorted list of items
List<MyObject>list = hash.get(key);

// clause to check for size
if (list.size() > 0) {

    // iterate through each item in the list and fetch obj
    for (int i=0; i < list.size(); i++) {
        MyObject be = list.get(i);

        // if object is not in hash, add to hash and point obj to new node
        if (!hashParents.containsKey(be)) {
                DefaultMutableTreeNode parent = 
                    new DefaultMutableTreeNode(be.getSequence());

                // add the key and jtree node to hash
                hashParents.put(be, parent);    

                // insert node to tree, relead model        
                ((DefaultMutableTreeNode)(root)).insert(
                    new DefaultMutableTreeNode("parent node"), 
                    root.getChildCount());
                    ((DefaultTreeModel)(tree.getModel())).reload();
        }

        // now that a parent-node exists, create a child 
        DefaultMutableTreeNode child = new DefaultMutableTreeNode("child");

        // insert the new child to the parent (from the hash)
        ((DefaultTreeModel)(tree.getModel())).insertNodeInto(child, hashParents.get(be), 
            hashParents.get(be).getChildCount());

        // render the tree visible          
        ((DefaultTreeModel)(tree.getModel())).reload();
    }
}
  • 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-06-08T23:14:23+00:00Added an answer on June 8, 2026 at 11:14 pm

    You make mistake here

    // insert node to tree, relead model        
    ((DefaultMutableTreeNode)(root)).insert(
       new DefaultMutableTreeNode("parent node"), 
       root.getChildCount());
    

    You already create node parent above, but don’t use it. You insert in tree another node, but child nodes you still insert in parent. That’s why they don’t appear in tree.

    This code fragment look like

    // insert node to tree, relead model        
    ((DefaultMutableTreeNode)(root)).insert(
       parent, 
       root.getChildCount());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a select list which is being populated using the values from a
This is all in C#, using .NET 3.5. I have a list populated with
I have a list which will store Number objects. The list will be populated
I have a jquery mobile list. This list is populated with data. I want
I have a GridView inside of a User Control populated from a List of
In Flex 4 (beta 2), I have a list control populated from an XMLListCollection.
I have a list populated with a sprite class I created. I use this
I'm running a dropdown list populated by column CustName from table Customer, and each
I currently have a dropdown list being populated with values from a database. I
I have a list view populated by an adapter reading from SQLite database. When

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.