How to use resource font directly in Java?
Asked
Active
Viewed 7,564 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
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
-
-
Using [`Font.deriveFont(float)`](https://docs.oracle.com/javase/10/docs/api/java/awt/Font.html#deriveFont(float)) – aioobe Mar 30 '23 at 16:27