📅  最后修改于: 2022-03-11 14:52:47.131000             🧑  作者: Mango
String text = "Hello World";
Font font = new Font("Arial", Font.PLAIN, 12);
FontRenderContext frc = new FontRenderContext(new AffineTransform(), true, true);
int textwidth = (int)(font.getStringBounds(text, frc).getWidth());
int textheight = (int)(font.getStringBounds(text, frc).getHeight());