How to use resource font directly in Java?
Asked
Active
Viewed 6,728 times
2
-
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 Answers
7
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
- 399,198
- 105
- 792
- 807