title: JTree single node foreground
body: <p>I know this question has been asked before in a similar way, maybe for icons.
  What I'm trying is to change the color of the text of the tree node.
  In fact, I have a jTree and I will want to set up three differents colors, default one, red and orange.</p>
  
  <p>The purposse, is that if I compare that tree with another one, highlight differences between both trees (default means no diff, orange means just value diff and red means node is complete different)</p>
  
  <p>I have two functions, one which trasverse the "original" tree looking for a node from the compared one, and returns false if {node} is not found:</p>
  
  <pre><code>private Boolean findNodeInRefTree(DefaultTreeModel model, Object root, DefaultMutableTreeNode node){
       Boolean bRet = false;
       for (int i = 0; ((i &lt; model.getChildCount(root))&amp;&amp;(!bRet)); i++){
           DefaultMutableTreeNode child = (DefaultMutableTreeNode) model.getChild(root, i);
           bRet = node.getUserObject().equals(child.getUserObject());
           if (!bRet)
               bRet = findNodeInRefTree(model, child, node);
       }//for:i
       return bRet;
  }
  </code></pre>
  
  <p>And another function that trasverse the "compare" tree and calls the above for each node.</p>
  
  <pre><code>private void compareTrees(TreeModel model, Object root){
  
      for (int i = 0; i &lt; model.getChildCount(root); i++){
          DefaultMutableTreeNode child = (DefaultMutableTreeNode) model.getChild(root, i);        
          //find if node exists in original
          DefaultTreeModel modelRef = (DefaultTreeModel) _ref.getModel();
          if (!findNodeInRefTree(modelRef, modelRef.getRoot(), child)){
              DefaultTreeCellRenderer render = (DefaultTreeCellRenderer) _temp.getCellRenderer();
              render.setForeground(Color.RED);
              _temp.setCellRenderer(render);
          }//fi            
          _new.insertNodeInto((DefaultMutableTreeNode) child, (DefaultMutableTreeNode) root, i);            
          compareTrees(model, child);
      }//for:i
  }
  </code></pre>
  
  <p>Then, when it ends I just set the model of the new tree {_new} to the new tree {_temp}, and add the tree to its panel. But the tree doesn't has any different color. Obviously, I'm testing with different trees. Any suggestion?</p>