我正在使用Java创建一个数字时钟,并且我已经做到了。现在我想在JLabel中设置显示时间的数字钟的字体。我正在应用以下代码的帮助下的字体。
try {
Font f1= new Font("Digital-7" ,Font.BOLD,28);
jLabel1.setFont(f1);
} catch(Exception ex) {
ex.printStackTrace();
}发布于 2013-06-29 17:27:17
+1条HovercrafFullOfEels评论。
我想我没有看到数字-7字体预装(好吧,至少不是在Windows上)也许你需要font file,然后你会加载字体文件,只有它才能使用。
有关加载字体文件并使用它的信息,请参见下面的内容(为了提高可读性,我省略了错误处理):
String filename="path/to/file/whatever.ttf";//this is for testing normally we would store the font file in our app (knows as an embedded resource), see this for help on that http://stackoverflow.com/questions/13796331/jar-embedded-resources-nullpointerexception/13797070#13797070
Font font = Font.createFont(Font.TRUETYPE_FONT, new File(filename));
font = font.deriveFont(Font.BOLD,28);
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
ge.registerFont(font);
JLabel l = new JLabel("Some Text");
l.setFont(font);https://stackoverflow.com/questions/17378625
复制相似问题