*
The moose likes Swing / AWT / SWT and the fly likes JTree - collapsePath issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTree - collapsePath issue" Watch "JTree - collapsePath issue" New topic
Author

JTree - collapsePath issue

Sainath Veepuri
Ranch Hand

Joined: Sep 25, 2003
Posts: 49


/**
* @desc Makes sure that only the given tree node path is expanded.
*/
private void singleExapand( TreePath prmNdPath ) {
Enumeration expandedPaths = this.getExpandedDescendants( new TreePath( _rootNode.getPath() ) );
boolean bExpandNode = true;
if( null != expandedPaths ) {
while( expandedPaths.hasMoreElements() ) {
TreePath expdPath = ( TreePath )expandedPaths.nextElement();
if( !prmNdPath.equals( expdPath ) ) {
this.collapsePath( expdPath );
bExpandNode = false;
}
}

}

oldPath = prmNdPath;
if( bExpandNode ) {
this.expandPath( prmNdPath );
this.scrollPathToVisible( prmNdPath );
}
}





output (sometimes - not reproducible always)

java.lang.ArrayIndexOutOfBoundsException: 2 >= 1
at java.util.Vector.removeElementAt(Unknown Source)
at javax.swing.tree.VariableHeightLayoutCache$TreeStateNode.collapse(Unknown Source)
at javax.swing.tree.VariableHeightLayoutCache$TreeStateNode.collapse(Unknown Source)
at javax.swing.tree.VariableHeightLayoutCache.setExpandedState(Unknown Source)
at javax.swing.plaf.basic.BasicTreeUI$TreeExpansionHandler.treeCollapsed(Unknown Source)
at javax.swing.JTree.fireTreeCollapsed(Unknown Source)
at javax.swing.JTree.setExpandedState(Unknown Source)
at javax.swing.JTree.collapsePath(Unknown Source)



Hi all,
My aim is to allow single node expansion on a JTree component. Above is the abstract from a class which I extended from JTree.
Would any one let me know if there is any thing I'am missing in the above code.
Whenever I try to load my tree component this exception comes.
The above exception is not reproducible all the time only some times.
any guesses whether why this happens?
Thank you,
Sainath Veepuri
[ October 04, 2005: Message edited by: Sainath Veepuri ]
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
I couldn't get your method to generate the exception you sited. Since the exception seems to have started with the 'collapsePath' call I would slip in a println statement to inspect what is coming into its test statement

 
It is sorta covered in the JavaRanch Style Guide.
 
subject: JTree - collapsePath issue
 
Similar Threads
JTree problem with parents
JTree problem
XML to DOM to JTree
Edit Values in a JTree
JTree refresh, with new TreeModel