Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Tree not expanding when new node inserted

Status
Not open for further replies.

Snowcrash

Programmer
Sep 1, 2002
31
AU
The following code although compiles without error, does not expand the nav tree to show the newly inserted node. What am I doing wrong here?

VCmpNavTreeNode savedNode = curHandler.requestSaveNavTreeNode( treeNode );

// Check that the returned node has been properly saved by
// checking that the Node is not null
if ( savedNode != null ) {
successfulSave = true;

JTree navTree = parentViewDu.getTree();
DefaultTreeModel navTreeModel = (DefaultTreeModel)
navTree.getModel();

if (editPolicy == Constants.Gen_AsNew) {
// For new, first build a new Node Object with
// all default blank values
// If saved, then add to tree
navTreeModel.insertNodeInto(
treeNode, parentTreeNode,
parentTreeNode.getChildCount()
);

// XXX This expansion doesn't work - don't know why !
// Get the index of the parentNode, and
// then expand the tree for the current index

int i =

navTreeModel.getChildCount
(this.parentTreeNode) - 1;
TreeNode[] theNodes = navTreeModel.getPathToRoot(
(TreeNode) navTreeModel.getChild(
this.parentTreeNode, i
)
);

TreePath theNodePath = new TreePath(theNodes);
navTree.expandPath(theNodePath);
navTree.repaint();

Thanks for any help in advance.

Snowcrash
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top