United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-8024777 : TitledBorder.getTitleFont() return null

Details
Type:
Bug
Submit Date:
2013-09-13
Status:
Resolved
Updated Date:
2013-11-14
Project Name:
JDK
Resolved Date:
2013-11-14
Component:
client-libs
OS:
windows_7
Sub-Component:
javax.swing
CPU:
Priority:
P3
Resolution:
Won't Fix
Affected Versions:
7u40
Fixed Versions:
7-pool

Related Reports
Relates:

Sub Tasks

Description
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 ?
                                    

Comments
The issue JDK-7022041 has not been backported to JDK 7
                                     
2013-09-16



Hardware and Software, Engineered to Work Together