0

I have a JTree which needs to be populated as the data is being loaded. I create tree with DefaultTreeModel

final DefaultTreeModel treeModel = new DefaultTreeModel(root);
jTree1 = new JTree(treeModel);

Where root is a MutableTreeNode implementation. When the data I need to show is changed or added a listener is triggered, which calls

public void exStateAdded(final ExState parent, ExState child) { 
final ExStateTreeNode exStateTreeNode = new ExStateTreeNode(child);
SwingUtilities.invokeLater(new Runnable() {
    @Override
    public void run() {
        treeModel.insertNodeInto(exStateTreeNode, root, root.getChildCount());

    }
});

Debugger shows, that insert is called, but tree itself doesn't reflect the change. If I call reload() the tree is drawn but it also collapses all the nodes. The model is changing and nodes are added correctly. What it is I am missing?

Dia
  • 271
  • 1
  • 13
  • 1
    please why deosn't works, no idea about any issue about, are you tested if TreeModelEvent notified about insertXxx, otherwise post an SSCCE, short, runnable, compilable with harcoded value for node(s) or TreeModel, – mKorbel Dec 19 '13 at 11:42
  • 2
    and before any code here to test `tree.makeVisible(path.pathByAddingChild(newNode));` and then `tree.scrollRectToVisible(tree.getPathBounds(path.pathByAddingChild(newNode)));` – mKorbel Dec 19 '13 at 11:45
  • tree.makeVisible(path) solves my problem. Thanks. – Dia Dec 19 '13 at 11:48
  • no way:-), not this not solve something :-) node is added correctly but off screen, – mKorbel Dec 19 '13 at 12:01

0 Answers0