JDK-7185204 : FontMetrics.stringWidth() does not return fixed value for same string
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 2.0,8
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows
  • CPU: generic
  • Submitted: 2012-07-19
  • Updated: 2012-10-18
  • Resolved: 2012-07-20
Related Reports
Duplicate :  
Description
Platform: Windows (I run the test on win7 ja and win7 zh_CN), Linux and maybe more
Java: Java 8 b45. This problem does not happen in earlier builds or release.

In command line interface, compile attached file, StringTest.java. Run StringTest more than one times in the console. For the same String, return value of FontMetrics.stringWidth() is often different.

The output of the program should be the same, but in different run, the output of StringTest is different.

If we use Java 8 b44 or Java 7, there is no such problem.

StringTest.java uses Toolkit.getDefaultToolkit().getFontMetrics(f) to get FontMetrics. Toolkit.getFontMetrics(Font f) is depericated now. I am not sure if this method causes the problem. I use JFrame.getFontMetrics to get the FontMetrics in another program, and in that case, the output of FontMetrics.stringWidth() does not change.

Toolkit.getFontMetrics(Font f) is not removed from Java API, though it's depricated. The testing program also works fine before 8 b45. I am also not sure if the problem is caused by Toolkit.getFontMetrics(Font f) because I can not try all the Java GUI components to get the FontMetrics.

Comments
EVALUATION The test strings hit the layout engine so this looks like a duplicate of 7183251. It started in the same build as that appeared and goes away with the fix.
20-07-2012

EVALUATION Seems like a 2d issue.
20-07-2012