java - Jar file not using custom font -
inside netbeans custom font loads set of code fails load when run program executable jar file
code
public static void main(string[] args) { arcanus arc = new arcanus(); try { font customfont = font.createfont(font.truetype_font, new file("golden-sun.ttf")).derivefont(12f); graphicsenvironment ge = graphicsenvironment.getlocalgraphicsenvironment(); ge.registerfont(font.createfont(font.truetype_font, new file("golden-sun.ttf"))); arc.setfont(customfont); } catch (ioexception e) { e.printstacktrace(); } catch (fontformatexception e) { e.printstacktrace(); } }
any apreciated
embedded resources should not read file
object. file
object used reading files in local file system. once file jarred, becomes resource , should read such. can read inputstream
using getclass().getresourceasstream()
. example
inputstream = getclass().getresourceasstream("/golden-sun.tff"); font font = font.createfont(font.truetype_font, is);
where golden-sun.tff
on class path (direct child of src
development)
root src golden-sun.tff
Comments
Post a Comment