我目前正在工作的项目需要我使用字体Helvetica,在我的Netbeans我没有选择在我的GUI中使用该字体,我怎么能得到它?
Try This:
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;
}
}