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

Incorrect Size for JTree Component

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 1.4.0
    • 1.3.0
    • client-libs
    • merlin
    • x86
    • windows_95



      Name: mc57594 Date: 01/05/2000


      JRE build 1.3beta-0
      Hotspot build 1.3beta-0


      The size of a JTree consisting of a mixture of tip nodes (no children) and
      internal nodes (have children) is incorrectly calculated. The size is based on
      the first item in the list of nodes. In the Java/Metal look-and-feel a tip node
      occupies more vertical space than an internal node. As a result if the tree
      contains a mixture of tip and internal nodes, and the first is an internal
      node, then the vertical space calculated for the tree is too small. If the
      first is a tip node, then too much vertical space is calculated.

      See attached program. Frames labelled TIP and NODE are correctly sized (and of
      a different size). Frame labelled MIX is too small. It is the same size as
      NODE, but should be between NODE and TIP.

      ---------------------------------------------------------------------------

      import javax.swing.*;
      import javax.swing.tree.*;
      import java.awt.*;

      public class Test3
      {
          public static void main(String[] args)
          {
              JFrame f = new JFrame("NODE");
              JPanel p = new JPanel();
              p.setLayout(new BorderLayout());
              DefaultMutableTreeNode tn = new DefaultMutableTreeNode("Root");
              addNode(tn, "1");
              addNode(tn, "2");
              addNode(tn, "3");
              addNode(tn, "4");
              addNode(tn, "5");
              addNode(tn, "6");
              addNode(tn, "7");
              addNode(tn, "8");
              JTree t = new JTree(tn);
              t.setVisibleRowCount(8);
              t.setRootVisible(false);
              p.add(new JScrollPane(t));
              f.getContentPane().add(p);
              f.pack();
              f.setVisible(true);

              f = new JFrame("TIP");
              p = new JPanel();
              p.setLayout(new BorderLayout());
              tn = new DefaultMutableTreeNode("Root");
              addTip(tn, "1");
              addTip(tn, "2");
              addTip(tn, "3");
              addTip(tn, "4");
              addTip(tn, "5");
              addTip(tn, "6");
              addTip(tn, "7");
              addTip(tn, "8");
              t = new JTree(tn);
              t.setVisibleRowCount(8);
              t.setRootVisible(false);
              p.add(new JScrollPane(t));
              f.getContentPane().add(p);
              f.pack();
              f.setVisible(true);

              f = new JFrame("MIX");
              p = new JPanel();
              p.setLayout(new BorderLayout());
              tn = new DefaultMutableTreeNode("Root");
              addNode(tn, "1");
              addTip(tn, "2");
              addTip(tn, "3");
              addTip(tn, "4");
              addTip(tn, "5");
              addTip(tn, "6");
              addTip(tn, "7");
              addTip(tn, "8");
              t = new JTree(tn);
              t.setVisibleRowCount(8);
              t.setRootVisible(false);
              p.add(new JScrollPane(t));
              f.getContentPane().add(p);
              f.pack();
              f.setVisible(true);
          }

          private static void addNode(DefaultMutableTreeNode tn, String tag)
          {
              DefaultMutableTreeNode x = new DefaultMutableTreeNode(tag);
              x.add(new DefaultMutableTreeNode("X"));
              tn.add(x);
          }

          private static void addTip(DefaultMutableTreeNode tn, String tag)
          {
              DefaultMutableTreeNode x = new DefaultMutableTreeNode(tag);
              tn.add(x);
          }
      }
      (Review ID: 99004)
      ======================================================================

            svioletsunw Scott Violet (Inactive)
            mchamnessunw Mark Chamness (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: