title: How can I remove an element from JTree without having it selected using .getSelectionPath()?
body: <p>I'm trying to remove an Element for my undo function but I want to just remove the last thing added to the JTree.</p>
  
  <p>For removal, I'm just modifying my method for Cut:</p>
  
  <pre><code>private void performUndoAction() {        
  
          if (tree != null) {
  
              TreePath path = tree.getSelectionPath();
              if (path != null) {
  
                  DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
                  if (node != tree.getModel().getRoot()) {
  
                      DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent();
                      if (node.getUserObject() instanceof Attribute) {
  
                          Attribute at = (Attribute) node.getUserObject();
                          at.getParent().removeAttribute(at);
                          cut = at;
                      }
                      else if (node.getUserObject() instanceof Element) {
  
                          Element el = (Element) node.getUserObject();
                          el.getParent().removeContent(el);
                          cut = el;
                      } else if (node.getUserObject() instanceof Text) {
  
                          cut = ((Text) node.getUserObject()).getText();
                          Element el = (Element) parent.getUserObject();
                          el.setText("");
                      }
                      parent.remove(node);
                      tree.updateUI();
                  }
              }
          } 
      }       
  </code></pre>