I am going to use custom font in my application. For that I am using Font.createFont()
method.
My code is given below. It works fine when I run my main class using command
java myAppl.class
The font file is in same directory that of my class file. But when I bundled all files and font files in JAR and then run my application from JAR, the custom font do not loaded. Why?
InputStream is = this.getClass().getResourceAsStream("myfont.TTF");
uniFont=Font.createFont(Font.TRUETYPE_FONT,is);
Font f = uniFont.deriveFont(24f);
What should I do?
InputStream
returned by getResourceAsStream()
for null
. If it is null
, that indicates the resources was not located.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With