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 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/

相关文章:

java - 将列文本旋转 60 度

java - Netbeans Servlet

java - 如何正确设置 twitter4j?

实体字段中的 Java 8 可选

java - 包含测试失败 Java 的列表

java - 如何在java中更新MongoDB的密码

java - 如何减少 Netbeans 中 JTable 的列?

java - 打印图形对象

java - 有没有办法用 netbeans 中的记录器替换所有 system.out/err 和 e.printstacktraces?

java - 在哪里可以找到startupApacheTomcat7.txt?