1String text = "Hello World";
2Font font = new Font("Arial", Font.PLAIN, 12);
3FontRenderContext frc = new FontRenderContext(new AffineTransform(), true, true);
4
5int textwidth = (int)(font.getStringBounds(text, frc).getWidth());
6int textheight = (int)(font.getStringBounds(text, frc).getHeight());