compute string height

Hi, can anybody tell me how to find the height of a string? SwingUtilities has a method to compute the width, but I also need the height. By "height", I mean the height of the tallest char in the string.Thanks
[230 byte] By [rvm11suna] at [2007-11-26 15:52:11]
# 1
RTFMlook up FontMetrics
tjacobs01a at 2007-7-8 22:12:25 > top of Java-index,Security,Cryptography...
# 2

> RTFM

>

I bet you feel important now

> look up FontMetrics

Maybe I should explain my problem in more detail. I am aware of methods like Font.getStringbounds(), TextLayout.getBounds() etc.

My problem is that I would like to draw a string, centered (heightwise) in a Graphics object (say for simplicity, a JLabel even though that is the purpose of a JLabel in the first place).

The formula to center anything is ((height of enclosing object - height of object to center) / 2) which gives you the y position, correct?

At this point, y = the distance from the top of the enclosing object to the top of the centered object. However, doing a graphics.drawString("Some string", 0, y) will not center the string because graphics.drawString requires y to be position of the baseline of the string.

So my question is (now) how to calculate y such that drawing the string at position y (using the Graphics.drawString method) will center the given string in the Graphics object.

I've been fiddling with the font's ascent values etc but I can't seem to make it work.

rvm11suna at 2007-7-8 22:12:25 > top of Java-index,Security,Cryptography...
# 3
> I've been fiddling with the font's ascent values etc> but I can't seem to make it work.You should have mentioned that, we can't read minds. Post what you have tried, and we might be able to help you.
CaptainMorgan08a at 2007-7-8 22:12:25 > top of Java-index,Security,Cryptography...