Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to obtain font/string metrics? (Ascent, descent, leading, and advance).

908740Jan 29 2012 — edited Jun 1 2012
Swing offered methods for obtaining font metrics for a font (ascent, the height the font extends above the baseline; descent, the height it extends below the baseline; and leading, the space between the top of this line and the bottom of the previous line, assuming the same font on both lines), and for calculating the width a string would take if it was displayed in a given font.

Unfortunately, this seems to have disappeared in JavaFX 2. I can see no good way of calculating the ascent, leading, or descent, and the only way I've been able to figure out to calculate the width of a piece of text is to make a Label from it and get the width of a label.

Surely there's got to be a good, simple, and officially approved way of calculating these measures? They are needed for any app that needs to do precise placement of text, eg. layout programs.

Thanks,
Ken McDonald
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 29 2012
Added on Jan 29 2012
3 comments
2,166 views