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

Strange behaviour of JTree makes it difficult to find own mistake

    XMLWordPrintable

Details

    • Bug
    • Resolution: Not an Issue
    • P5
    • None
    • 6
    • client-libs

    Description

      FULL PRODUCT VERSION :
      java version "1.6.0"
      Java(TM) SE Runtime Environment (build 1.6.0-b105)
      Java HotSpot(TM) Client VM (build 1.6.0-b105, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      When not connecting the treemodel correctely to the jtree the tree behaves itself strangely which makes it difficult to find one own's mistake.

      (see source code)
      One would expect that nothing would happen when calling addNode(). Effectively the first node is added. But after calling addNode() again no more nodes are added but the vertical lines of the tree-angles are disapearing (so one thinks the model is connected to the tree correctely because the tree changes its look in a strange way..).

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      compile and run the sourcecode


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javax.swing.*;
      import javax.swing.tree.*;
       
      public class Strange
      {
          static class MyTree extends JTree
          {
      static DefaultMutableTreeNode root = new DefaultMutableTreeNode("Root");
      static DefaultTreeModel treeModel = new DefaultTreeModel( root );
       
      public MyTree()
      {
      super( root );
      }
       
      public void addNode()
      {
      DefaultMutableTreeNode newNode = new DefaultMutableTreeNode("New Node");
      treeModel.insertNodeInto( newNode, root, root.getChildCount() );
      expandPath( new javax.swing.tree.TreePath(root) );
      }
          }
       
      public static void main(String[] args)
      {
      JFrame jframe = new JFrame();
      MyTree mytree = new MyTree();

      jframe.add(mytree);
              jframe.setBounds( 50, 50, 300, 200 );
      jframe.setVisible( true );

      mytree.addNode();
      mytree.addNode();
      mytree.addNode();
      }
      }

      ---------- END SOURCE ----------

      Attachments

        Activity

          People

            svioletsunw Scott Violet (Inactive)
            tyao Ting-Yun Ingrid Yao (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: