我正在尝试在我的程序中将自定义字体(bilboregular.ttf)设置为 2 个 jLabels 但字体未成功加载。
以下是主要方法调用:
//this should work if the build is in a jar file, otherwise it'll try to load it directly from the file path (i'm running in netbeans)
if (!setFonts("resources/bilboregular.ttf")) {
System.out.println("=================FAILED FIRST OPTION"); // <<<<<<<< This is being displayed
if(!setFonts(System.getProperty("user.dir")+"/src/resources/bilboregular.ttf")){
System.out.println("=================FAILED SECOND OPTION"); // <<< This is not being displayed
}
}
这是另一种方法:
public boolean setFonts(String s) {
try {
jLabel3.setFont(java.awt.Font.createFont(java.awt.Font.TRUETYPE_FONT, new java.io.File(s)));
jLabel4.setFont(java.awt.Font.createFont(java.awt.Font.TRUETYPE_FONT, new java.io.File(s)));
return true;
} catch (Exception ex) {
return false;
}
}