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?