java.awt.Font类提供了 static Font createFont(int fontFormat, File fontFile) Returns a new Font using the specified font type and the specified font file. static Font createFont(int fontFormat, InputStream fontStream) Returns a new Font using the specified font type and input data.
Font font = null; String fName = "A.ttf"; //Test try { InputStream is = DemoFonts.class.getResourceAsStream(fName); font = Font.createFont(Font.TRUETYPE_FONT, is); } catch (Exception ex) { ex.printStackTrace(); System.err.println(fName + " not loaded. Using serif font."); font = new Font("serif", Font.PLAIN, 24); } return font;
JLabel label = new JLabel(); label.setFont(new Font("Serif", Font.PLAIN, 12));
static Font createFont(int fontFormat, File fontFile)
Returns a new Font using the specified font type and the specified font file.
static Font createFont(int fontFormat, InputStream fontStream)
Returns a new Font using the specified font type and input data.
String fName = "A.ttf"; //Test
try {
InputStream is = DemoFonts.class.getResourceAsStream(fName);
font = Font.createFont(Font.TRUETYPE_FONT, is);
} catch (Exception ex) {
ex.printStackTrace();
System.err.println(fName + " not loaded. Using serif font.");
font = new Font("serif", Font.PLAIN, 24);
}
return font;
JLabel label = new JLabel();
label.setFont(new Font("Serif", Font.PLAIN, 12));