Text width/height
How do I find out the size of rendered text?
Specifically, I want to draw text in the middle of a JPanel. Something like this:
Except, of course, that getTextWidth and getTextHeight don't exist, so what do I need to use?
Specifically, I want to draw text in the middle of a JPanel. Something like this:
public void paint (Graphics g)
{
int x = getWidth()/2 - getTextWidth ("String")/2;
int y = getHeight()/2 - getTextHeight ("String")/2;
g.drawString ("String", x, y);
}
Except, of course, that getTextWidth and getTextHeight don't exist, so what do I need to use?
