I have a problem with creating a node in the JTree

Hello All!
I have a problem when I try to create a new node in the JTree. If the parent node of the new node has any other children, I get following NullPointerException exception :
java.lang.NullPointerException
     at javax.swing.plaf.basic.BasicTreeUI.startEditing(BasicTreeUI.java:1959)
     at javax.swing.plaf.basic.BasicTreeUI.startEditingAtPath(BasicTreeUI.java:506)
     at javax.swing.JTree.startEditingAtPath(JTree.java:1921)
     at ru.sirena2000.jxt.iface.action.TreeActionHandler.createNode(TreeActionHandler.java:62)
It seems to me, that path of creating node was not defined in the BasicTreeUI.
Note, if the parent node has no other children, the new node will be successfully created. How can I solve this problem? Help me, please!
I use java version 1.4.2-b28

Sorry, I forgot to show a piece of code, where I try to create a new node. This piece of code see above. "tree.scrollPathToVisible(path);" is a string, which throws an exception.
tree.repaint();
TreePath path = tree.getSelectionPath();
if (path == null) {
return;
if (tree.isCollapsed(path)) {
tree.expandPath(path);
DefaultMutableTreeNode parentNode =
(DefaultMutableTreeNode)path.getLastPathComponent();
IconData childData = defineIconData(parentNode);
IconData newData = childData.copy();
newData.getNodeObject().clearNodeObj();
newData.getNodeObject().setNodeText("New");
DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(newData);
editingData = newData;
editingData.getNodeObject().setStatus(TreeNodeData.NEW_STATUS);
parentNode.add(newNode);
DefaultTreeModel model = (DefaultTreeModel)tree.getModel();
path = path.pathByAddingChild(newNode);
tree.scrollPathToVisible(path);
tree.startEditingAtPath(path);
saveChangesInBuffer(newNode, TreeNodeData.NEW_STATUS);
model.nodeStructureChanged(parentNode);

Similar Messages

Maybe you are looking for