title: JTree dynamic node insertion
body: <p>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.</p>
  
  <p>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.</p>
  
  <pre><code>// an unsorted list of items
  List&lt;MyObject&gt;list = hash.get(key);
  
  // clause to check for size
  if (list.size() &gt; 0) {
  
      // iterate through each item in the list and fetch obj
      for (int i=0; i &lt; 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();
      }
  }
  </code></pre>