`

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"));
	}

 

分享到:
评论
1 楼 avd羲羲 2012-04-23  
FontMetrics fm = sun.font.FontDesignMetrics.getMetrics(f);    sun.font是啥啊???

相关推荐

Global site tag (gtag.js) - Google Analytics