Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6985555

uiswing - components - Null pointer ex in DynamicTreeDemo.java example

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Fix
    • Icon: P4 P4
    • None
    • 6-pool
    • docs
    • 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

            Unassigned Unassigned
            skannan Sowmya Kannan (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: