Monday December 15, 2008 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]
| « November 2009 | ||||||
| Sun | Mon | Tue | Wed | Thu | Fri | Sat |
|---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | |||||
| Today | ||||||
Today's Page Hits: 75