0
点赞
收藏
分享

微信扫一扫

JAVA ttf字体转化为Font

public static Font ttf2font(String filePath, int fontStyle, int fontSize) {
	File fontFile = new File(filePath);
	Font font = null;
	try {
		font = Font.createFont(Font.TRUETYPE_FONT, fontFile);
		font = font.deriveFont(fontStyle, fontSize);
	
	} catch (FontFormatException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	
	return font;
}

类似这样使用:

t.setFont(TextArea.ttf2font("./Consolas.ttf", Font.BOLD, 20));

举报

相关推荐

0 条评论