Home > javafx > "Can JavaFX speak my language?"

"Can JavaFX speak my language?"

An attempt to answer two simple questions…

  • Can JavaFX speak my language?
  • How to load custom fonts in JavaFX?

There are many languages for which Java does not provide built-in support. Also you may want to use some nice custom font instead of the logical font. You may also want to ensure that the application looks fine across platforms and does not render boxes or look ugly on some platforms.

JavaFX allows you to package your font along with the application. So that you can use the font with your application and its guaranteed that the application looks fine on all platforms. Here I’ll try to render some characters using my mother tongue – Malayalam. Oh! Yes! its a palindrome.

First I downloaded Malayalam font from Indix website. I’ll use RRRaghuMalayalam.ttf in my application.

I copied the RRRaghuMalayalam.ttf font file under src/fontttf/fonts/ directory. fontttf is package name of the application. Next I created a mapping file – fonts.mf under src/META-INF/. In mapping file I specified a name for the font and the location of font as shown below. I named the font as Malayalam Font.

Malayalam\ Font = /fontttf/fonts/RRRaghuMalayalam.ttf

Now the directory structure looks as shown below.

Now lets use this new font in our application. That is simple!.
We can just specify the font name as “Malayalam Font”.
No additional settings required.

Text {
    font: Font {
        name: "Malayalam Font"
        size: 40
    content: "\u0d2e\u0d32\u0d2f\u0d3e\u0d33\u0d02"

For Applet mode, click on above image

For standalone mode

Cool! Now JavaFX can speak my language! Can it speak your language?

You need to try it out!


var dzone_url = “http://blogs.sun.com/rakeshmenonp/entry/javafx_custom_fonts”;
var dzone_style = ‘2’;

digg_skin = ‘compact’;
digg_window = ‘new’;

Categories: javafx Tags: , ,
  1. Farrukh Obaid
    March 20, 2009 at 3:17 PM

    Thanks Rakesh great work..
    Another question i hope u donot mind..
    How to open web page in browser in JavaFX..
    there is method AppletExtension.browse() this doesnot work.. it is doable in java class by using Desktop d=Desktop.getDesktop() and then d.browse(URL) it works… but can we do this in javaFX

  2. March 23, 2009 at 3:55 AM

    AppletStageExtension.showDocument(url, target) API will work only if the application is deployed in browser mode. So I think for now Desktop.browse(URI) is better alternative.

  3. Jothi Prem Sanker
    May 17, 2009 at 2:39 AM

    I am getting square boxes…. Please tell about how to configure manifest. I am using netbeans 6.5.1. I did all that above, but not getting. I dont know where i did mistake. Please help me. I is needed in my project.

  4. June 11, 2009 at 2:48 AM

    @Jothi Prem Sanker Manifest file is here http://blogs.sun.com/rakeshmenonp/resource/FontTTF/fonts.mf Are you using new set of font and text? Are you able to run above sample?

  5. Ernie Kent
    August 28, 2009 at 4:37 PM

    Thank you for this, Rakesh. I would also like to be able to download and use a user-selected font from a large collection on the server. However I cannot seem to get JavaFX to allow me to use registerFont() on the downloaded font. Is this possible? Or is there some other way to do it?
    Thank you!

  6. September 4, 2009 at 5:22 AM

    @Ernie Kent I haven’t tried using registerFont (JDK 1.6 API), will check with other engineers and get back to you. Can you file an issue at http://javafx-jira.kenai.com/ and let me know ID?

  7. Ernie Kent
    September 4, 2009 at 12:13 PM

    Thanks, Rakesh. I posted it as RT-5606

  8. September 7, 2009 at 4:44 AM

    @Ernie Kent Thanks.. I have outlined a solution here, let me know if this works for you..

  9. September 7, 2009 at 1:43 PM

    Looks like a great solution, Rakesh!
    Many thanks!

  10. Sony George
    October 4, 2009 at 6:12 AM

    my question is,
    why sun is not implementing the above code in
    netbeans to display property files ??
    you can not view Malayalam in property files created by netbeans even though java is a Unicode language.
    see the link

  11. Rakesh Menon
    October 25, 2009 at 8:33 PM

    @Sony George May be netbeans must provide option to specify the font to be used, or it must automatically detect the unicode range and select font automatically. Anyway I think you can try Font2DTest which comes with JDK to view the files (for now) $JAVA_HOME/demo/jfc/Font2DTest/Font2DTest.jar

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: