• Post Reply Bookmark Topic Watch Topic
  • New Topic

why m i getting error on deleting nodes on a fixed index?????

 
S Rubia
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
At the following code.................................................

public void treeCollapsed(TreeExpansionEvent e)
{
Object o=e.getPath().getLastPathComponent();
int index=treeModel.getChildCount(o);
System.out.println("Child counted: "+index);
for(int i=1; i<index ; i++)
{
DefaultMutableTreeNode node=(DefaultMutableTreeNode)treeModel.getChild(o , 1);
System.out.println("child selected is: "+node);
treeModel.removeNodeFromParent(node);
}
}


i got this error..........................................................................................Why???


Child counted: 3
child selected is: servlets
Exception occurred during event dispatching:
java.lang.ArrayIndexOutOfBoundsException: 2 >= 2
at java.util.Vector.elementAt(Vector.java:417)
at javax.swing.tree.DefaultMutableTreeNode.getChildAt(DefaultMutableTree
Node.java:231)
at javax.swing.tree.DefaultTreeModel.getChild(DefaultTreeModel.java:151)

at NodeHandler.treeCollapsed(NodeHandler.java:62)
at javax.swing.JTree.fireTreeCollapsed(JTree.java:2156)
at javax.swing.JTree.setExpandedState(JTree.java:2770)
at javax.swing.JTree.collapsePath(JTree.java:1671)
at javax.swing.plaf.basic.BasicTreeUI.toggleExpandState(BasicTreeUI.java
:2033)
at javax.swing.plaf.basic.BasicTreeUI.handleExpandControlClick(BasicTree
UI.java:2009)
at javax.swing.plaf.basic.BasicTreeUI.checkForClickInExpandControl(Basic
TreeUI.java:1963)
at javax.swing.plaf.basic.BasicTreeUI$MouseHandler.mousePressed(BasicTre
eUI.java:2674)
at java.awt.Component.processMouseEvent(Component.java:3714)
at java.awt.Component.processEvent(Component.java:3546)
at java.awt.Container.processEvent(Container.java:1164)
at java.awt.Component.dispatchEventImpl(Component.java:2595)
at java.awt.Container.dispatchEventImpl(Container.java:1213)
at java.awt.Component.dispatchEvent(Component.java:2499)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:2451
)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:2210)
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!