Results 1 to 2 of 2
  1. #1
    rru96 is offline Senior Member
    Join Date
    Sep 2012
    Posts
    107
    Rep Power
    0

    Default *SOLVED* Package Font into Jar

    I am trying to package a font in with a jar file. I dropped the font file into a res folder and put it in the build path. And using the code below, I am able to get the font to display correctly while within Eclipse. The problem is if I export my file to a runnable JAR file, I cannot get the file to open at all, even though it runs fine in Eclipse.

    Java Code:
    public void loadFont(){
    		try{
    			fontFile = new File(getClass().getResource("/CANDARAB.TTF").toURI());
    			font = new Font("Candara", Font.BOLD, 90);
    			font2 = new Font("Candara", Font.BOLD, 30);
    			font3 = new Font("Candara", Font.BOLD, 20);
    		}catch(URISyntaxException e){
    			e.printStackTrace();
    			System.out.println("File Failed to Load");
    		}
    		try{
    			GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    			ge.registerFont(Font.createFont(Font.TRUETYPE_FONT, fontFile));
    		}catch(FontFormatException | IOException f){
    			f.printStackTrace();
    		}
    	}
    Whenever I commented out this code, the rest works perfectly. Is this the proper way to load and register a font within a jar file?
    Last edited by rru96; 10-03-2013 at 05:39 AM.

  2. #2
    rru96 is offline Senior Member
    Join Date
    Sep 2012
    Posts
    107
    Rep Power
    0

    Default Re: Package Font into Jar

    UPDATE: I looked around online some and decided to try and run my jar from the command line. I did so and end up with the following:
    Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: URI is not hierarchical.

    The first numbered line it points to is line 3 of the above code.
    Changing this line to
    Java Code:
     fontFile = new File("/CANDARAB.TTF");
    seems to have solved the problem.

Similar Threads

  1. Replies: 2
    Last Post: 03-26-2013, 06:07 PM
  2. Replies: 3
    Last Post: 03-27-2012, 09:27 AM
  3. Replies: 0
    Last Post: 08-18-2010, 10:31 AM
  4. Replies: 7
    Last Post: 11-09-2009, 07:51 AM
  5. Replies: 5
    Last Post: 04-25-2009, 08:00 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •