aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes importing a .ttf file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "importing a .ttf file " Watch "importing a .ttf file " New topic
Author

importing a .ttf file

Chris Dancy
Ranch Hand

Joined: Feb 14, 2006
Posts: 136
i noticed that in the api there was a setFont method for JFrame. Now this is what i was wondering. Is it possible to import(by import i mean code it in) a .ttf file into the class and get it to change the font for the entire frame to the custom one i want imported. I tried to do this on my own buy to no avail i got nothing. I just want to be able to include the .ttf file with my program, probably in a jar, and have it that new Font be used throughout my entire ui, without setting to each additional component. I just need help coding this, cause i tried and nothing, if anyone has any solutions that would be great.


("Anger is not an emotion, its a symptom of fear.")
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
1. You can include font files in a jar, like any other resource, then access them through Font's static createFont method, which can be passed an InputStream.

2. You can use javax.swing.UIManager and UIDefaults to change the look-and-feel defaults before you create any swing components. It's easy: here's a demo. I preserved the font's style (bold, italic) but I increased the size 20%. For this code to work, the ttf file must be in in the same place (directory or directory-in-jar) as the class file.


There is no emoticon for what I am feeling!
Chris Dancy
Ranch Hand

Joined: Feb 14, 2006
Posts: 136
Thanks for the help. Ive been struggling with this for quite sometime trying to get it to work. Thanks for the sample code too, it really helps.

Sincerely,

Chris Dancy
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: importing a .ttf file
 
Similar Threads
External Font usage
Font differs from Windows and Linux ?
Packaging Fonts?
External Font usage
How to create a ttf font using java