Naoko Hamamoto's Weblog

« JavaFX Localization | Main | JavaFX Localization... »

20081215 Monday December 15, 2008

JavaFX Localization Part 2

In my previous posting, I had some problems with the rendered fonts. In this posting, I explain a couple of different ways to fix the problem.

1. Set Font Type in JavaFX Script

Instead of relying on the default, I explicitly specify the font type.

Replace

===================================================
SwingLabel {height: 30 width: 250 text: v1},
SwingLabel {height: 30 width: 250 text: v2},
SwingLabel {height: 30 width: 250 text: v3},
SwingButton {height: 30 width: 250 text: v4},
SwingButton {height: 30 width: 250 text: v5}
===================================================

with

===================================================
SwingLabel {height: 30 width: 250 text: v1 font: Font{name: "MS Gothic", size: 20}},
SwingLabel {height: 30 width: 250 text: v2 font: Font{name: "MS Gothic", size: 20}},
SwingLabel {height: 30 width: 250 text: v3 font: Font{name: "MS Gothic", size: 20}},
SwingButton {height: 30 width: 250 text: v4 font: Font{name: "MS Gothic", size: 20}},
SwingButton {height: 30 width: 250 text: v5 font: Font{name: "MS Gothic", size: 20}}
===================================================

Let me also make the fonts a little bigger. Now it looks a lot better.

However, this approach makes the script no longer universal - different font types will be required for different locales. Here is another (and better) way to fix this problem - thanks to Naoto-san for his help!

2. Set Look and Feel to System Default in JavaFX Script

Here, I specify Look and Feel (aka LAF) to the system default in the script. I am testing on Mac OSX. The default LAF used is javax.swing.plaf.metal.MetalLookAndFeel. For Mac OSX, it is better if I use its own LAF: apple.laf.AquaLookAndFeel. In any case, the following snippet does the trick for any OS.

===================================================
var dLAF = UIManager.getSystemLookAndFeelClassName();
UIManager.setLookAndFeel(dLAF);
===================================================

Oh don't forget to import the UIManager class. Also don't forget to remove the hardcoded font declarations from the script.

===================================================
import javax.swing.UIManager;
===================================================

Now when I execute it, this is what I get.

Oh this looks so much nicer!

FYI - a bug has been for this issue, see this: Swing based FX apps look worse comparing to the Swing native apps on MacOSX. Please vote if you think it should be fixed!

Posted by naoko ( Dec 15 2008, 12:50:37 PM PST ) Permalink Comments [0]

Trackback URL: http://blogs.sun.com/naoko/entry/javafx_localization_part_2
Comments:

Post a Comment:

Name:
E-Mail:
URL:

Your Comment:

HTML Syntax: NOT allowed

Valid HTML! Valid CSS!

This is a personal weblog, I do not speak for my employer.