title: A editable JTree converts the tree nodes into Strings
body: <p>I'm using a JTree that is populated from a database. </p>
  
  <p>The tree is created by setting the root node and its childs with custom objects this way: </p>
  
  <pre><code>private DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode("Categorias");
  ...
  ResultSet primaryCategories = dbm.fetchAllCategories();
  while (primaryCategories.next()){
      Category category = new Category(primaryCategories.getLong("_id"), 
              primaryCategories.getString("category"));
      DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(category);
      rootNode.add(childNode);
  
      ResultSet currentSubcategory = dbm.fetchChildSubcategories(category.getCatId());
      while (currentSubcategory.next()){
          Category subcategory = new Category(currentSubcategory.getLong("_id"), 
                  currentSubcategory.getString("category"));
          childNode.add(new DefaultMutableTreeNode(subcategory, false));
      }
  }
  ...
  </code></pre>
  
  <p>After this, the tree is perfectly created. Populated with "<strong>Category</strong>" Objects, every object has its own ID number and its name to use in toString() method.</p>
  
  <p>The problem comes when it's set editable. Once the node is renamed, the <strong>Category</strong> node is also converted into a <strong>String</strong> Object, so I cant update the new Category name value to the database.</p>
  
  <p>I've tried to capture the renaming event with <code>treeNodesChanged(TreeModelEvent e)</code> but, the userObject is already changed to a String Object, and can't get a referece of what object was edited.</p>
  
  <p>What way can I solve this? Should I have a copy of the tree that's shown and another of the downloaded from the database and uptade both everytime a change occurs?</p>
  
  <p>*<em>PD: *</em>
  I also tried to capture the changed node from the model overriding the method:</p>
  
  <pre><code>public void nodeChanged(TreeNode newNode) {
     DefaultMutableTreeNode parent = ((DefaultMutableTreeNode)newNode.getParent());
      int index = getIndexOfChild(parent, newNode);
      DefaultMutableTreeNode oldNode = (DefaultMutableTreeNode) getChild(parent, index);
      System.out.println(parent.getUserObject().getClass().toString());
      System.out.println(oldNode.getUserObject().getClass().toString());          
  }
  </code></pre>
  
  <p>this prints:</p>
  
  <pre><code>class com.giorgi.commandserver.entity.Category
  class java.lang.String
  </code></pre>
  
  <p>So the old node here has already been changed to a String and I've lost completely the reference to the older Category and its ID so I cannot update it in the database.</p>
  
  <p>Any help is wellcome.</p>