gpt4 book ai didi

java - 将字体导入 Netbeans

转载 作者:行者123 更新时间:2023-12-01 13:15:39 24 4
gpt4 key购买 nike

我正在从事的项目目前要求我使用 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com