Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use resource font directly in Java

Tags:

java

How to use resource font directly in Java?

like image 919
SamSol Avatar asked Feb 18 '26 22:02

SamSol


1 Answers

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.

like image 137
aioobe Avatar answered Feb 21 '26 11:02

aioobe