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 |