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

REGRESSION: deselecting node in JTree throws NPE.

XMLWordPrintable

    • b50
    • sparc
    • solaris_9

      In the sample JTree app given below, when i try to do CTL-CLICK to deselect a selected node, it throws a NPE. This happens on win2k and Winxp in JDK1.5 only.

      In DefaultRenderer i return null for background and NonSelectionBackground color.


      import javax.swing.*;
      import javax.swing.tree.*;
      import java.awt.*;
      public class JTreeTest {
      public static void main(String[] args) throws Exception{
      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
      //UIManager.put("Tree.drawDashedFocusIndicator",Boolean.FALSE);
              JFrame fr = new JFrame("JTreeTest");
              DefaultMutableTreeNode root = new DefaultMutableTreeNode("root");
              DefaultTreeModel model = new DefaultTreeModel(root);
              DefaultMutableTreeNode ch1 = new DefaultMutableTreeNode("A",true);
              DefaultMutableTreeNode ch2 = new DefaultMutableTreeNode("B",true);
              root.add(ch1);
              root.add(ch2);
              ch1.add(new DefaultMutableTreeNode("1"));
              ch1.add(new DefaultMutableTreeNode("2"));
              ch1.add(new DefaultMutableTreeNode("3"));
              ch2.add(new DefaultMutableTreeNode("4"));
              JTree tr = new JTree(model);
              tr.setCellRenderer(new DefaultTreeCellRenderer() {
      public Color getBackgroundNonSelectionColor(){
      return null;
      }
      public Color getBackground(){
      return null;
      }

      });
      fr.getContentPane().add(tr);
      fr.setSize(200,200);
             fr.setVisible(true);
             fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

      }
      }
      ###@###.### 2005-2-04 09:25:59 GMT

            svioletsunw Scott Violet (Inactive)
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: