title: Rendering a JTree leaf with a JPanel containing an editable JTextArea
body: <p>I am trying to render a JTree leaf to have a JPanel containing an editable JTextArea so that a user can type in text and be able to scroll down as they adding text, </p>
  
  <p>and also using a wrapper to limit the text in width so it stretches down to allow more space rather scrolling left and right. </p>
  
  <p>I have implemented the following so far but it appears weird, when I run the code, as if there are two leafs, the default one and the rendered on. Any type of help is highly appreciated. </p>
  
  <p>I just want to know if what I am want to do is achievable and if not, where can I modify. </p>
  
  <p>I don't want to change the icons, just the leaf only. </p>
  
  <pre><code>import java.awt.Component;
  import java.awt.event.ComponentEvent;
  import java.awt.event.ComponentListener;
  import java.awt.event.ItemEvent;
  import java.util.EventObject;
  import javax.swing.*;
  import javax.swing.tree.DefaultTreeCellRenderer;
  import javax.swing.tree.TreeCellEditor;
  import javax.swing.tree.TreeCellRenderer;
  
  /**
   *
   * @author Razaractor
   */
  class LeafRenderer extends AbstractCellEditor implements
          TreeCellRenderer, TreeCellEditor {
  
      //Text area to be place on JPanel
      JTextArea text = new JTextArea();
      DefaultTreeCellRenderer nonLeafRenderer = new DefaultTreeCellRenderer();
  
      @Override
      public Object getCellEditorValue() {
          return text.getText();
      }
  
      @Override
      public boolean isCellEditable(final EventObject event) {
          return true;
      }
  
      @Override
      public Component getTreeCellRendererComponent(
              final JTree tree, final Object value,
              final boolean selected,
              final boolean expanded,
              final boolean leaf,
              final int row,
              final boolean hasFocus) {
          //Default leaf
          Component render = nonLeafRenderer.getTreeCellRendererComponent(tree,
                  value, selected, expanded, leaf, row, hasFocus);
          if (selected &amp;&amp; leaf) {
              final JPanel panel = new JPanel();
              BoxLayout layout = new BoxLayout(panel, BoxLayout.X_AXIS);
              panel.setLayout(layout);
              text.setColumns(20);
              text.setLineWrap(true);
              text.setRows(5);
              text.setWrapStyleWord(true);
              text = new JTextArea(String.valueOf(value));
              text.addComponentListener(new ComponentListener() {
  
                  @Override
                  public void componentResized(ComponentEvent e) {
                      panel.setSize(panel.getPreferredSize());
                  }
  
                  @Override
                  public void componentShown(ComponentEvent e) {
                  }
  
                  @Override
                  public void componentMoved(ComponentEvent e) {
                  }
  
                  @Override
                  public void componentHidden(ComponentEvent e) {
                  }
              });
              JScrollPane scroll = new JScrollPane(text);
              panel.add(scroll);
              render = panel;
              return panel;
          }
          return render;
      }
  
      @Override
      public Component getTreeCellEditorComponent(
              final JTree tree,
              final Object value,
              final boolean isSelected,
              final boolean expanded,
              final boolean leaf,
              final int row) {
          Component editor = nonLeafRenderer.getTreeCellRendererComponent(tree,
                  value, true, expanded, leaf, row, true);
          final JPanel p = new JPanel();
          if (editor instanceof JPanel) {
              editor = (JPanel) editor;
          }
          return editor;
      }
  
      public void itemStateChanged(ItemEvent itemEvent) {
          if (stopCellEditing()) {
              fireEditingStopped();
          }
      }
  }
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/ADhEp.jpg" alt="enter image description here"></p>
  
  <p><img src="https://i.stack.imgur.com/iBknZ.jpg" alt="enter image description here"></p>