Search |
||
Unicode support in JavaFX ScriptPosted by joconner on July 12, 2007 at 5:08 PM PDT
I was pleasantly surprised with my first real interaction with JavaFX Script. Of course, I had to test at least one of its i18n features, so I picked something simple, Unicode text in the script. My goal was simple. Find out whether I could successfully create a simple "Hello, world" using non-ASCII characters. I picked Japanese since I'm familiar with that language. The translation accuracy doesn't matter much as long as it generated hiragana and kanji text, so I typed my first script into NetBeans after creating a JavaFX Project:
import javafx.ui.*;
Frame {
title: "Hello World JavaFX"
width: 200
height: 50
content: Label {
text: "こんにちは、世界!"
}
visible: true
}
Then I saved this script as Running the script confirmed my thoughts:
Fortunately, I know exactly what's wrong. It's the charset conversion when I save the file. Converting the Japanese text to 8859-1 loses data; see all those '?' marks in the above image. That's the giveaway. I have to escape the non-ASCII Japanese characters in my script. It's a pain, a big pain, but I'm used to this sort of problem in both property files and code source files. So I just escape the chars as shown here:
...
content: Label {
text: "\u3053\u3093\u306b\u3061\u306f\u3001\u4e16\u754c\uff01"
}
...
Now I try again. Save, recompile, run, and...nice.
This wasn't a complete test of JavaFX Script's ability to display Unicode characters, but it does clarify a few things for me. A script's character encoding has the same limitations as a Java resource file. For now at least, the easiest way to get non-ASCII characters into a JFX script is to escape them. It's not easy to remember the Unicode codepoint value for all characters. That's simply not the way people type characters into any editor. So you'll probably have to use the JDK tool For now I'm just happy to report that you can embed Unicode chars into your JavaFX Script files. Just remember to encode them with the --- »
Related Topics >>
Netbeans Comments
Comments are listed in date ascending order (oldest first)
|
||
|
|