【发布时间】:2014-01-12 23:18:29
【问题描述】:
我试图在我的 JFrame 中使用一种特殊字体,但我遇到了问题。我有一个这样定义的 JLabel:
private JLabel lab = new JLabel("Text");
我有一个名为 CUSTOMFONT-MEDIUM.TTF(TrueType 字体)的文件,但在编写以下内容后:
try {
lab.setFont(Font.createFont(Font.TRUETYPE_FONT, getClass().getResource("/CUSTOMFONT-MEDIUM.TTF").openStream()));
} catch(IOException ex){
//exception handled here I suppose
} catch(FontFormatException ex2) {
//same here
}
代码编译,一切正常,除了“实验室”没有显示,所以没有文本。我想这是因为我从未指定字体大小应该是什么,但我所做的任何尝试都失败了。有人可以帮我吗?
【问题讨论】: