> 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.