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

TitledBorder.getTitleFont() return null

XMLWordPrintable

      FULL PRODUCT VERSION :
      C:\Program Files\Java\jdk1.7.0_40\jre\bin>java.exe -version
      java version "1.7.0_40"
      Java(TM) SE Runtime Environment (build 1.7.0_40-b43)
      Java HotSpot(TM) Client VM (build 24.0-b56, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP Professional Version 2002 Service Pack 3
      Microsoft Windows 7

      A DESCRIPTION OF THE PROBLEM :
      Calling the method getTitleFont() on an Instance of TitledBorder Class return a null value.


      REGRESSION. Last worked in version 6u43

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      TitledBorder tb = new TitledBorder("Titled Border");
      Font tbFont = tb.getTitleFont();
      System.out.println(tbFont);

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The Font returned should be the one defined by the current look and feel as described in the javadoc of TitledBorder class

      * If the border, font, or color property values are not
       * specified in the constuctor or by invoking the appropriate
       * set methods, the property values will be defined by the current
       * look and feel, using the following property names in the
       * Defaults Table:
       * <ul>
       * <li>&quot;TitledBorder.border&quot;
       * <li>&quot;TitledBorder.font&quot;
       * <li>&quot;TitledBorder.titleColor&quot;
       * </ul>
      ACTUAL -
      The returned value is null

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      TitledBorder tb = new TitledBorder("Titled Border");
      Font tbFont = tb.getTitleFont();
      System.out.println(tbFont);
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      A workaround could be passing the default font in the constructor call

      TitledBorder tb = new TitledBorder(BorderFactory.createEtchedBorder(), "Titled Border",
      TitledBorder.LEADING, TitledBorder.DEFAULT_POSITION, UIManager.getFont("TitledBorder.font"));

      In Java 1.6.0_21 the getTitleFont method implementation looks like this:
      public Font getTitleFont() {
              Font f = titleFont;
      if (f == null)
          f = UIManager.getFont("TitledBorder.font");
              return f;
          }

      In java 1.7.x the if statement is missing!
      Why this change in the implementation ?

            alexp Alexander Potochkin (Inactive)
            coffeys Sean Coffey
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: