Last time I had to work with the JTree class, I decided that it was one of the worst parts of Swing, and as of my current project, my mind is unchanged When the UI is initialized, there are no game objects in the world yet so the tree is empty (constructed using a null root node). So, when the root object is added I need to add a root node for it and update the tree:
public void create(final MyTreeNode root)
{
rootNode = root;
model = new MyTreeModel(root); //Inherits DefaultTreeModel; currently doesn't override anything
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
setModel(model);
model.reload(); //I'm not sure if both of these are needed
model.nodeStructureChanged(root);
}
});
}
But, this has no effect–the tree is still blank. I found some stuff about a treeStructureChanged() event in the TreeModelListener, but I couldn’t find a way to fire it. How do I change the model?