java中获取字符串宽度
public static void main(String[] args) {
Font f = new Font("宋体", Font.BOLD, 12);
FontMetrics fm = sun.font.FontDesignMetrics.getMetrics(f);
// 高度
System.out.println(fm.getHeight());
// 单个字符宽度
System.out.println(fm.charWidth("A"));
// 整个字符串的宽度
System.out.println(fm.stringWidth("宋A"));
}
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。