Java Graphics How to - Load font from ttf file








Question

We would like to know how to load font from ttf file.

Answer

//from  ww w .j  av  a  2s .  c o  m
import java.awt.Font;
import java.io.InputStream;

public class Main {
  public static void main(String[] a) throws Exception {
    String fName = "/fonts/A.ttf";
    InputStream is = Main.class.getResourceAsStream(fName);
    Font font = Font.createFont(Font.TRUETYPE_FONT, is);

  }
}