Results 1 to 5 of 5
- 12-20-2012, 08:51 PM #1
Member
- Join Date
- Dec 2012
- Posts
- 3
- Rep Power
- 0
Weird issue with Chinese characters
We are having difficulty with a program (which currently exists as both an Eclipse plug-in and as a Windows standalone executable; at least the Eclipse plug-in uses org.eclipse.swt classes, and presumably the Windows standalone is from the same codebase) that theoretically should have no trouble displaying Chinese characters, yet it does, at least for us.
Our Chinese contract developer (in China) has no trouble with displaying (and entering) Chinese text in the program from his machine:

chines by Tracker-Backer, on Flickr
. . . yet all I get, viewing the same data in the same program (I selected a single-record view, whereas his screen shot shows a multi-record view) is a string of "substitute boxes."

failed by Tracker-Backer, on Flickr
So I banged out this simple Swing application:
which has no trouble at all displaying Chinese characters:Java Code:package test20dec2012; import java.util.*; import java.awt.*; import java.awt.geom.*; import java.awt.image.*; import java.awt.datatransfer.*; import java.awt.event.*; import java.awt.print.*; import java.io.*; import javax.swing.*; public class Test20Dec2012 { static String foo = "\u8FD9\u662F\u4E2D\u6587"; public static void main(String[] args) { JTextField bar = new JTextField(foo); JOptionPane.showMessageDialog(null, bar); } }

test20dc2012 by Tracker-Backer, on Flickr
Any idea why the production application works on a box in China, but not on my box, even though the test application works fine?
- 12-21-2012, 04:05 AM #2
Member
- Join Date
- Dec 2012
- Posts
- 74
- Rep Power
- 0
Re: Weird issue with Chinese characters
I don't know. Could it be a difference in the font?
- 12-21-2012, 07:29 PM #3
Member
- Join Date
- Dec 2012
- Posts
- 3
- Rep Power
- 0
Re: Weird issue with Chinese characters
I have more information since the original post:
It seems that an old Swing client program (from which the recalcitrant programs were derived) has no trouble at all displaying the Chinese characters properly from the live data, so long as either (a) I select one of the Java symbolic font names (e.g., "Dialog"), or (b) I run it on my Macintosh.
This suggests that it is indeed a matter of font rendering, and that the presence (implicit on the Mac) or absence (on the WinDoze XP box, unless it's explicitly installed) of "East Asian Language Support" is also a factor: the Firefox browser can render Chinese Unicode without requiring such support, and the Swing UI classes can do so if the Java "logical fonts" are used.
Unfortunately I don't know enough about the org.eclipse.swt UI classes to do anything about this myself.
- 12-22-2012, 02:41 AM #4
- 12-27-2012, 12:23 AM #5
Member
- Join Date
- Dec 2012
- Posts
- 3
- Rep Power
- 0
Re: Weird issue with Chinese characters
Turns out I was being stupid and pig-headed.
To have SWT applications render Chinese text properly in WinDoze XP (and presumably any other version of WinDoze in which East Asian Language Support is not built in), you need only install the East Asian Language Support option, a process that requires your installation media and a restart, and is done from the same control panel you use to set your locale (but you don't actually have to set your locale).
I realized why this is when I researched what SWT is, and how it works: Swing and SWT take diametrically opposite approaches to the inadequacies of AWT.
Swing strives for complete platform independence, doing everything in Java that it possibly can, while SWT strives for the closest possible integration with the platform, letting the OS do everything it possibly can. Therefore, it would make perfect sense for a Swing-based application to be able to display Chinese text independently of any OS-level support, while an SWT application to be totally dependent on such OS-level support.
While I still don't know enough about SWT to code my way out of a paper bag by calling it (and I still definitely prefer Swing, if I'm doing something in Java that requires a UI), at least I now understand something about the SWT approach, and the consequences thereof.
Similar Threads
-
Chinese characters in Excel
By Jayashreevmenon in forum Advanced JavaReplies: 4Last Post: 08-04-2011, 10:51 AM -
Need to write chinese characters to csv file
By Jayashreevmenon in forum Advanced JavaReplies: 0Last Post: 08-04-2011, 10:50 AM -
Certain Chinese Characters not displayed properly.
By kerwintang in forum Advanced JavaReplies: 1Last Post: 08-21-2009, 05:55 AM -
Displaying Chinese characters on Swing components
By vaskarbasak in forum AWT / SwingReplies: 3Last Post: 06-26-2008, 08:27 AM -
drawString with Chinese Characters
By vaskarbasak in forum Advanced JavaReplies: 1Last Post: 06-10-2008, 07:49 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks