0

I need to create a java.awt.Font object for my project and it needs to be available for the whole application. I cannot install the font to the system and any help regarding creating the font object in the runtime is needed. My JDK is 1.7.0_17 and my code is the following.

try {
    Font f = Font.createFont(Font.TRUETYPE_FONT, new File("DL-Paras...ttf"));
    jLabel1.setFont(f);
} catch (Exception ex) {
    ex.printStackTrace();
}

Can objects be called like the system properties throughout the application instance? Thanks in advance.

EDIT: Thank you all, I got the answer.

  • @AndrewThompson Don't know about duplicate, but a nice answer none-the-less +1 – MadProgrammer Apr 19 '13 at 04:07
  • @MadProgrammer It is the `registerFont(Font)` method I was thinking that makes this a duplicate. Once registered, it can be used like any other `Font`. Of course, if the OP is thinking more along the lines of setting a font in lust one place and have it used for components thereafter, they need to tweak the Pluggable Look & Feel. – Andrew Thompson Apr 19 '13 at 04:33
  • 1
    @AndrewThompson After re-reading the question a few dozen more times, I think you're right – MadProgrammer Apr 19 '13 at 04:35
  • please isn't about UIManager `....available for the whole application instance in...` – mKorbel Apr 19 '13 at 06:39
  • @isu3ru are you meaning that your Font could be used, changed, applied for all JComponents (`jLabel1.setFont(f);`), ??? – mKorbel Apr 19 '13 at 06:41
  • Thank you all, for the support. @AndrewThompson, @MadProgrammer, @mKorbel and all. the code snippet from the question (http://stackoverflow.com/questions/8364787/how-do-you-import-a-font) did the trick. `GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); ge.registerFont(font);` Thank you very much. – Isuru Ranawaka Apr 19 '13 at 10:19
  • 1
    You can [answer your own question](http://meta.stackexchange.com/q/17463/163188). – trashgod Apr 19 '13 at 11:34
  • Thanks for all your support. I found the answer here on this post. :) http://stackoverflow.com/questions/12730230/set-the-same-font-for-all-component-java Thanks again. This is the best support website ever! – Isuru Ranawaka Sep 22 '13 at 06:23

0 Answers0