1

I have a JTree that I have linked with an XML Doc using DOM4J. I have a popup that allows me to add nodes where I select.

public void addNode() {
        BranchTreeNode node = (BranchTreeNode) getLastSelectedPathComponent();
        if ((node.getXmlNode() instanceof Element)
                && (node.getXmlNode().getName().equals(ROOT))) {
            Element root = (Element) node.getXmlNode();
            Element element = root.addElement(NODE);            
        }
    }

This works great for the underlying XML, I can save it and read it perfectly. the problem is it will only add one single node in the tree and no matter how many nodes I add it will only display one, and that one's one child and so forth. Ive tried

treeModel.reload(); 
treeModel.reload(node);
treeModel.nodeChanged(node);

and just now, looking up the spelling in eclipse this hilariously worked

treeModel.setDocument(treeModel.getDocument());

So I guess my question now is: Is this the correct way to do it? Am I missing something?

mKorbel
  • 109,525
  • 20
  • 134
  • 319
user1681732
  • 97
  • 1
  • 8

0 Answers0