2014-03-19 76 views
0

我正在處理的項目目前需要我使用字體Helvetica,在我的Netbeans中我沒有在我的GUI中使用該字體的選項,我怎樣才能得到它?將字體導入到Netbeans

回答

1

試試這個:

 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; 
} 
}