Results 1 to 5 of 5
  1. #1
    Join Date
    Dec 2012
    Posts
    6
    Rep Power
    0

    Cool 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:

    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);
    }
    }
    which has no trouble at all displaying Chinese characters:


    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?

  2. #2
    kaydell2 is offline Senior Member
    Join Date
    Dec 2012
    Posts
    106
    Rep Power
    0

    Default Re: Weird issue with Chinese characters

    I don't know. Could it be a difference in the font?

  3. #3
    Join Date
    Dec 2012
    Posts
    6
    Rep Power
    0

    Default 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.

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,244
    Rep Power
    19

    Default Re: Weird issue with Chinese characters

    Quote Originally Posted by hbquikcomjamesl View Post
    I don't know enough about the org.eclipse.swt UI classes to do anything about this myself.
    Moved from Advanced Java

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    Join Date
    Dec 2012
    Posts
    6
    Rep Power
    0

    Default 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

  1. Chinese characters in Excel
    By Jayashreevmenon in forum Advanced Java
    Replies: 4
    Last Post: 08-04-2011, 10:51 AM
  2. Need to write chinese characters to csv file
    By Jayashreevmenon in forum Advanced Java
    Replies: 0
    Last Post: 08-04-2011, 10:50 AM
  3. Certain Chinese Characters not displayed properly.
    By kerwintang in forum Advanced Java
    Replies: 1
    Last Post: 08-21-2009, 05:55 AM
  4. Displaying Chinese characters on Swing components
    By vaskarbasak in forum AWT / Swing
    Replies: 3
    Last Post: 06-26-2008, 08:27 AM
  5. drawString with Chinese Characters
    By vaskarbasak in forum Advanced Java
    Replies: 1
    Last Post: 06-10-2008, 07:49 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •