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

BasicTreeUI.getPreferredSize(JComp c) is delegated to getPreferredSize(c, true) not (c, false)

    XMLWordPrintable

Details

    • b132
    • generic
    • generic
    • Verified

    Description

      The spec for
      http://download.java.net/jdk7/docs/api/javax/swing/plaf/basic/BasicTreeUI.html#getPreferredSize(javax.swing.JComponent)

      says

         "... this is a cover method for getPreferredSize(c, false)."

       There is a typo "checkConsistancy" -> "checkConsistEncy"

      But the main problem is that this assertion is not satisfied by RI.
      The call is delegated as (c, true), source code clearly shows that:
      --- start BasicTreeUI.java ---
          /** Returns the preferred size to properly display the tree,
            * this is a cover method for getPreferredSize(c, false).
            */
          public Dimension getPreferredSize(JComponent c) {
              return getPreferredSize(c, true);
          }
      --- end BasicTreeUI.java ---

      This code is the same for JDK7, JDK6 and JDK5

      Please see the following code sample as another illustration:

      ---
      import javax.swing.*;
      import javax.swing.plaf.basic.BasicLookAndFeel;
      import javax.swing.plaf.basic.BasicTreeUI;
      import java.awt.*;

      public class Test {

          public static void main(String[] args) {
              SwingUtilities.invokeLater(new Runnable() {
                  @Override
                  public void run() {
                      try {
                          UIManager.setLookAndFeel(new BasicLookAndFeel() {
                              public String getName() { return "testName"; }
                              public String getID() { return "testID"; }
                              public String getDescription() { return "testDescription"; }
                              public boolean isNativeLookAndFeel() { return false; }
                              public boolean isSupportedLookAndFeel() { return true; }
                          });
                      } catch (UnsupportedLookAndFeelException e) {
                          throw new RuntimeException(e);
                      }

                      JTree tree = new JTree();
                      tree.setUI(
                              new BasicTreeUI() {
                                  @Override
                                  public Dimension getPreferredSize(JComponent c, boolean checkConsistency) {
                                      System.out.println("Test.getPreferredSize(JComponent, boolean)");
                                      System.out.println("checkConsistency = " + checkConsistency);
                                      return super.getPreferredSize(c, checkConsistency);
                                  }
                              }
                      );
                      tree.setPreferredSize(null);
                      // call will be delegated to getPreferredSize(JComponent)
                      tree.getPreferredSize();
                  }
              });
          }
      }
      ---

      The output will be:

      Test.getPreferredSize(JComponent, boolean)
      checkConsistency = true

      Attachments

        Activity

          People

            alexp Alexander Potochkin (Inactive)
            dbessono Dmitry Bessonov
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: