Cmerf486
asked on
JTree Refresh
I am using a JTree in my application that needs to be abel to have nodes added to it and removed from it dynamically. Using the following function, everything works, but after one node has been added, any subsequent nodes I add don't show up in the JTree. There are no Exceptions thrown and I can reference the node programmatically. Is there something special I need to do to update the display? Any help would be appreciated. Thank you.
public void addTransition( Transition transition )
{
DefaultMutableTreeNode node = new DefaultMutableTreeNode( transition );
try
{
transitionNode.add( node );
treLayoutTree.scrollPathToVisible( new TreePath( node.getPath() ) );
}
catch ( Exception e )
{
Main.getLogger().writeToLogWarn( "MainWindow.addTransition() Exception: " + e.getMessage() );
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
(I edited before zzynx comment was showed... so I wasn't referring to him/her)
ASKER
Thanks a lot!
ASKER
zznyx,
Thanks for your entry and help!
MicheleMarcon,
Yours proved to be an easy solution, thanks. Here is my new code for anyone who might run into the same problem.
Thanks for your entry and help!
MicheleMarcon,
Yours proved to be an easy solution, thanks. Here is my new code for anyone who might run into the same problem.
public void addTransition( Transition transition )
{
DefaultMutableTreeNode node = new DefaultMutableTreeNode( transition );
try
{
((DefaultTreeModel)(treLayoutTree.getModel())).insertNodeInto( node, transitionNode, transitionNode.getChildCount() );
}
catch ( Exception e )
{
Main.getLogger().writeToLogWarn( "MainWindow.addTransition() Exception: " + e.getMessage() );
}
}
/**
* Invoke this method if you've totally changed the children of
* node and its childrens children... This will post a
* treeStructureChanged event.
*/
public void nodeStructureChanged(TreeN
So, add the nodes you want.
Then perform the above method on the parent node