-
Bug
-
Resolution: Won't Fix
-
P4
-
None
-
6-pool
-
generic
-
generic
The DynamicTreeDemo.java example works well but throws an NPE when editing the root node. I suggest the following change to DynamicTree.java:
class MyTreeModelListener implements TreeModelListener {
public void treeNodesChanged(TreeModelEvent e) {
DefaultMutableTreeNode node;
node = (DefaultMutableTreeNode) (e.getTreePath().getLastPathComponent());
/*
* If the event lists children, then the changed node is the child of the node we've already gotten. Otherwise, the changed node and the specified
* node are the same.
*/
if (e.getChildIndices() != null) {
int index = e.getChildIndices()[0];
node = (DefaultMutableTreeNode) (node.getChildAt(index));
}
System.out.println("The user has finished editing the node.");
System.out.println("New value: " + node.getUserObject());
}
The original URLs were:
http://download.oracle.com/javase/tutorial/uiswing/examples/components/DynamicTreeDemoProject/src/components/DynamicTreeDemo.java
http://download.oracle.com/javase/tutorial/uiswing/examples/components/DynamicTreeDemoProject/src/components/DynamicTree.java
class MyTreeModelListener implements TreeModelListener {
public void treeNodesChanged(TreeModelEvent e) {
DefaultMutableTreeNode node;
node = (DefaultMutableTreeNode) (e.getTreePath().getLastPathComponent());
/*
* If the event lists children, then the changed node is the child of the node we've already gotten. Otherwise, the changed node and the specified
* node are the same.
*/
if (e.getChildIndices() != null) {
int index = e.getChildIndices()[0];
node = (DefaultMutableTreeNode) (node.getChildAt(index));
}
System.out.println("The user has finished editing the node.");
System.out.println("New value: " + node.getUserObject());
}
The original URLs were:
http://download.oracle.com/javase/tutorial/uiswing/examples/components/DynamicTreeDemoProject/src/components/DynamicTreeDemo.java
http://download.oracle.com/javase/tutorial/uiswing/examples/components/DynamicTreeDemoProject/src/components/DynamicTree.java