Results 1 to 3 of 3
Thread: font in jar file not loading
- 10-26-2011, 09:31 PM #1
font in jar file not loading
I have a font, called calg.otf, that i am using in a program. My code works fine when run through eclipse but when i compile it to a jar it stops working;
how can i fix this to read from the root of a jar file?Java Code://global variables private Font calg; private Font de = new Font("Calibre", Font.PLAIN, 22); private Font font; //the call public Thing(){ ... calg = grabFont(); } //the method public Font grabFont(){ try{ URI uri = getClass().getResource("calg.otf").toURI(); File file = new File(uri); font = Font.createFont(Font.TRUETYPE_FONT, file); return font.deriveFont(40.0f); }catch(Exception e){ g2d.setFont(de); g2d.setColor(Color.GREEN); g2d.drawString("Error! Returning font serif to allow the continue of execution", 30, 30); repaint(); } return de.deriveFont(22.0f); }
- 10-27-2011, 12:50 AM #2
Re: font in jar file not loading
i figured it out. instead of using file i just used this in my try statement
i think that file cannot read from jar file directories. when i used a url to get the file.Java Code:Font font = Font.createFont(Font.TRUETYPE_FONT, getClass().getResourceAsStream("calg.otf")); return font.deriveFont(40.0f);
- 10-27-2011, 12:04 PM #3
Similar Threads
-
Set Font Color, Font Style & Font Family While Replacing Text
By sherazam in forum Java SoftwareReplies: 0Last Post: 08-18-2010, 10:31 AM -
How to change font/ font color etc in a graphic object using JCombobox?
By JavaInLove in forum AWT / SwingReplies: 5Last Post: 04-25-2009, 08:00 PM -
loading a text file
By nick2price in forum New To JavaReplies: 2Last Post: 12-24-2008, 12:46 AM -
Loading of JSP file failed
By Heather in forum JavaServer Pages (JSP) and JSTLReplies: 2Last Post: 08-06-2007, 01:15 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks