Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to load embedded font as InputStream from jar in java?

If I run the application from Eclipse, then all be done. But If export it to jar i get an Exception.

java.io.IOException: Problem reading font data.
at java.awt.Font.createFont(Unknown Source)

Here is the package tree

enter image description here

And my code (In the SzervizPrint.java file):

InputStream istream = getClass().getResourceAsStream("/resources/SerpentineBolditalic.ttf");
Font myFont = Font.createFont(Font.TRUETYPE_FONT, istream);
myFont = myFont.deriveFont(36.0f);
lblNewLabel.setFont(myFont);
like image 683
Dénes Levente Sávoli Avatar asked Jan 07 '13 09:01

Dénes Levente Sávoli


1 Answers

SerpentineBolditalic.ttf

Should be:

SerpentineBoldItalic.ttf 

(capital 'I')

While the local file system might not be case sensitive, getResource(String) most definitely is.

like image 184
Andrew Thompson Avatar answered Nov 06 '22 03:11

Andrew Thompson