Basic HTML version of Foils prepared 13 July 98

Foil 15 Centering a String Vertically

From Java Academy II:Intermediate Java NPAC/ECS Java Academy -- February to April 98. by Tom Scavo

The FontMetricsTest2 Applet
Vertical centering is independent of s: int appletHeight = getSize().height; int ascent = fm.getAscent(); int descent = fm.getDescent(); int stringHeight = ascent + descent; int y = ascent + (appletHeight - stringHeight )/2; g.drawString( s, x, y ); where x is computed as in the previous foil
Note: We add ascent to y since the latter is with respect to the string's baseline



© Northeast Parallel Architectures Center, Syracuse University, npac@npac.syr.edu

If you have any comments about this server, send e-mail to webmaster@npac.syr.edu.

Page produced by wwwfoil on Sat Nov 28 1998