我正在从事的项目目前要求我使用 Helvetica 字体,在我的 Netbeans 中我没有在 GUI 中使用该字体的选项,我怎样才能获得它?
最佳答案
试试这个:
You can SetFont for component using font class
Font f=new Font("Helvetica",Font.BOLD,20);
setFont(JComponent);
或使用:
public class FontLoader {
public static Font loadFont(float size, int style, JLabel j) {
Font font = null;
InputStream is = j.getClass().getResourceAsStream("starv___.ttf");
try {
font = Font.createFont(Font.TRUETYPE_FONT, is);
font = font.deriveFont(size);
font = font.deriveFont(style);
} /*catch (FileNotFoundException fe) {
System.out.println("File not found"); // was in here because i tried a file instead of an InputStream
} */catch (FontFormatException ex) {
System.out.println("Font is null1");
} catch (IOException e) {
System.out.println("Font is null2");
}
return font;
}
}
关于java - 将字体导入 Netbeans,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22496277/