Java 将字体导入Netbeans
我目前正在从事的项目要求我使用Helvetica字体,在我的Netbeans中,我没有在GUI中使用该字体的选项,我如何获得该字体?尝试以下方法:Java 将字体导入Netbeans,java,netbeans,Java,Netbeans,我目前正在从事的项目要求我使用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
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;
}
}
或使用:
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;
}
}