How to use Open Type Fonts in Java?

Open Type (.otf) font files are not supported in Java 1.6. From Java 1.7, support is added:

Font font = Font.createFont(Font.TRUETYPE_FONT, new File("MyFont.otf"));
font  = font.deriveFont(Font.BOLD, 40);

label.setFont(font);

More details:

  • http://bugs.java.com/view_bug.do?bug_id=6992611
  • http://docs.oracle.com/javase/7/docs/webnotes/adoptionGuide/#swing

Java OpenType font support depends on your OS and JDK version.

Prior to Java 6, you can only use TrueType flavored OpenType fonts. With Java 6 you can use all OpenType fonts but you won't benefit from advanced typographic features like ligatures.


I don't think there is Open Type Font support in java (not free atleast), iText claimed to have such support, tried it a few month ago and it didn't work, what worked for me is a program called FontForge which I used to create a ttf from the otf which I then used.