2

How to use resource font directly in Java?

SamSol
  • 2,885
  • 6
  • 37
  • 56
  • Can you clarify what are you trying to do? At the simplest level you can just create a new Font(...) and draw using it with Graphics.setFont(...) and Graphics.drawString(...) – mikera May 29 '10 at 12:01
  • 3
    @SamSol: Just out of curiosity, what on earth are you working on? I see you've asked dozens of questions about seemingly random and unrelated topics with only a few minutes inbetween. – Matti Virkkunen May 29 '10 at 12:08

1 Answers1

9

To load a font (.ttf) from file, have a look at Load font from ttf file.

Key lines being:

InputStream is = DemoFonts.class.getResourceAsStream(fName);
font = Font.createFont(Font.TRUETYPE_FONT, is);

The font could then be used for a JLabel through the usual setFont method.

aioobe
  • 413,195
  • 112
  • 811
  • 826