📌  相关文章
📜  如何在java代码示例中获取字符串的宽度和高度

📅  最后修改于: 2022-03-11 14:52:47.131000             🧑  作者: Mango

代码示例1
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());