• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

importing a .ttf file

 
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Chris Dancy
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic