Chinese Characters in JFrame Titlebar

Hi, we have created a application, mainly intended for chinese users. Based on the user's choice the application will start up with the appropriate resource bundle. However, while using the chinese resource bundle, everything is working perfectly, except that the JFrame/JDialog titles are not showing the chinese characters. Can anyone please help me out on this?
Thanx in advance,
Regards,
Debopam.

From all the information I've read (since I had the same problem) the titles for JFrames can only be viewed in foreign characters when you're running on the foreign OS. A couple of people overcame it by writing their own Frame code, but if you're running on XP you can just install Microsoft's AppLocale (http://www.microsoft.com/globaldev/tools/apploc.mspx).

Similar Messages

  • Displaying Chinese Characters in JFrame

    I was trying out some sample code in "Java Internationalization" for Chinese, and I am having problems viewing Chinese characters in JFrame. They show up as squares/rectangles instead of glyphs. I read that I needed to download Microsoft's Arial Unicode. I went to the site and discovered that Microsoft's TrueType core fonts for the Web are no longer available for download.
    Am I doing something wrong in the code? If the code is OK what should I do?
    The following is code based out of the O'Reilly book:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class NoInChinese extends JPanel {
    static JFrame frame;
    static String aSentence = "No in Chinese is, \u4e0d.";
    public NoInChinese(String characters) {
    Font theFont = new Font("Bitstream Cyberbit", Font.PLAIN, 20);
    JTextArea area = new JTextArea(characters, 2, 30);
    area.setFont(theFont);
    area.setLineWrap(true);
    JScrollPane scrollpane = new JScrollPane(area);
    add(scrollpane);
    public static void main(String argv[]) {
    NoInChinese chinesePanel = new NoInChinese(aSentence);
    frame = new JFrame("Test");
    frame.addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) {System.exit(0);}
    frame.getContentPane().add("Center", chinesePanel);
    frame.pack();
    frame.setVisible(true);
    Aggie

    Thanks fsato4, i have set the font to SimSun and can display the chinese char in unicode.
    However, i modified the source code a little to read from resource bundle. Here's my codes:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.util.Locale;
    import java.util.ResourceBundle;
    import java.text.MessageFormat;
    public class NoInChinese extends JPanel {
      static JFrame frame;
      static String aSentence = "No in Chinese is, \u4e0d.";
      Font font = new Font("SimSun",Font.PLAIN, 12);
      private static ResourceBundle messages;
      public NoInChinese(Locale currentLocale,String characters) {
        messages = ResourceBundle.getBundle("rb",currentLocale);
        JTextArea area = new JTextArea(characters, 10, 30);
        area.setFont(font);
        area.setLineWrap(true);
        area.append(System.getProperty("line.separator"));
        // this line will show glyph.
        //area.append(convert(messages.getString("FileMenu")));
        // this line will show the correct char
        area.append(convert(messages.getString("FileMenu")));
        area.append(System.getProperty("line.separator"));
        area.append(convert(messages.getString("EditMenu")));
        area.append(System.getProperty("line.separator"));
        area.append(convert(messages.getString("CancelMenu")));
        JScrollPane scrollpane = new JScrollPane(area);
        add(scrollpane);
      public static String convert(String theString) {
        String theNewString = theString;
        // String encoding = "CP1252";
        String encoding = "ISO-8859-1";
        String newEncoding = "GB18030";
        if (newEncoding != null) {
          try {
            byte[] convertedBytes = theString.getBytes(encoding);
            theNewString = new String(convertedBytes, newEncoding);
          } catch (Exception e) {
            System.err.println("Not able to convert " +
                                encoding + " " + newEncoding);
        return theNewString;
      public static void main(String args[]) {
        Locale currentLocale = new Locale("zh", "CN");
        NoInChinese chinesePanel = new NoInChinese(currentLocale,aSentence);
        frame = new JFrame("Test");
        frame.addWindowListener(new WindowAdapter() {
          public void windowClosing(WindowEvent e) {System.exit(0);}
        frame.getContentPane().add("Center", chinesePanel);
        frame.pack();
        frame.setVisible(true);
    }If i just read the unicode string from the resource bundle and display, glyph char will display. I have to use the convert method to read in as encoding "ISO-8859-1" then form a new string with GB18030, then i am able to see the display correctly.
    Why is this so?
    My resource bundle file looks like that:
    FileMenu=\u00ce\u00c4\u00bc\u00fe
    EditMenu=Edit
    CancelMenu=\u00c5\u00c5\u00b3\u00fd
    Thank you!

  • Chinese characters in JDialog title?

    Hi all,
    I'm running the JDK on an english language machine, but starting a program with the command line prompt -Duser.language=zh to display Chinese characters.
    If I have some chinese characters in a JDialog title, or a JOptionPane message or title, the characters are replaced with boxes. I can see Chinese characters everywhere else, in JLabels, text boxes, JTrees, etc, so its not a problem with fonts.
    Has anybody else had this problem? Is there a work around for this? Is it something to do with the UIManager setting the fonts for JOptionPane's?
    thanks,
    Justin

    Try calling these at the start of your app before showing any windows:
    JFrame.setDefaultLookAndFeelDecorated(true);
    JDialog.setDefaultLookAndFeelDecorated(true);
    If that doesn't work, I don't know what would. The default is that the OS draws the frame titlebar, and on English systems, it's not going to display chars that aren't in the charset. I'm sure you could change that by installing other charsets, but you can't really do that on other people's machines.

  • Why Chinese characters not showing up in JLabel correctly , sometimes ?

    I have a large program which uses a JLabel to display some Chinese characters in html, it was doing fine until the program grew larger and larger, then only html fonts in certain sizes will show up correctly, other sizes of the same fonts will show up as rectangles. It's not because it doesn't have these fonts, but it seems to be related to the complexity of the program. If I change the characters in rectangles to a different size ( smaller or larger ), they might show up correctly again (in the large program).
    I have a small test program below to see if a particular font size would show up correctly, they all showed up fine in this test, but if I try to display the same html in my large program, some sizes of characters will go wrong. I've even printed out the unicode and looked at them (6309 4f60 7684 9700 8981 ...), they are definitely in the Chinese character range.
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    public class Java_Test extends JPanel
      static int Total=900;
      JComboBox ComboBox_Array[]=new JComboBox[Total];
      Font Times_New_Roman_15_Font=new Font("Times New Roman",0,15);
      static int Small_Chinese_Font_Size=3;
      static String Software_Info_Chinese_Text="<Html><Table Width=100% Border=0 Cellpadding=2 Cellspacing=3><Tr><Td Align=Center><Font Size=6 Color=#3737FF>[ \u4EA7\u54C1\u7BA1\u7406 ] </Font></Td></Tr>"+
                                               "<Tr><Td Align=Center><Font Size=5 Color=green>\u5E2E\u52A9\u4F60\u7BA1\u7406\u4EA7\u54C1, \u5408\u540C, \u53CA\u5176\u5B83\u4FE1\u606F :</Font></Td></Tr>"+
                                               "<Tr><Td>\u8F93\u5165<Font Size="+Small_Chinese_Font_Size+" Color=#2255BB>"+
                                                 "<li>\u8F93\u5165, \u7EF4\u62A4\u548C\u6253\u5370\u8BE6\u7EC6\u4EA7\u54C1\u53CA\u4F9B\u8D27\u5546\u4FE1\u606F<Br>"+
                                                 "<li>\u5730\u5740\u548C\u5907\u6CE8\u4FE1\u606F\u53EF\u7528\u591A\u79CD\u8BED\u8A00\u8F93\u5165<Br>"+
                                               "</Font></Td></Tr>"+
                                               "</Table></Html>";
      JPanel Main_Panel=new JPanel();
      static boolean Exit_When_Window_Closed=false;
      Java_Test(String Test_String)
        for (int i=0;i<Total;i++) ComboBox_Array=new JComboBox();
    JLabel A_Non_English_Label=new JLabel(Test_String);
    A_Non_English_Label.setFont(Times_New_Roman_15_Font);
    A_Non_English_Label.setForeground(Color.BLUE);
    add(A_Non_English_Label);
    setPreferredSize(new Dimension(600,300));
    void Show_Up()
    Main_Panel.add(this);
    Dimension Screen_Size=Toolkit.getDefaultToolkit().getScreenSize();
    final JFrame frame=new JFrame("Java Test");
    frame.add(Main_Panel);
    frame.addWindowListener(new WindowAdapter()
    public void windowClosing(WindowEvent e) { if (Exit_When_Window_Closed) System.exit(0); }
    public void windowDeiconified(WindowEvent e) { Main_Panel.repaint(); }
    public void windowGainedFocus(WindowEvent e) { Main_Panel.repaint(); }
    public void windowOpening(WindowEvent e) { Main_Panel.repaint(); }
    public void windowResized(WindowEvent e) { Main_Panel.repaint(); }
    public void windowStateChanged(WindowEvent e) { Main_Panel.repaint(); }
    frame.pack();
    frame.setBounds((Screen_Size.width-Main_Panel.getWidth())/2,(Screen_Size.height-Main_Panel.getHeight())/2-10,Main_Panel.getWidth(),Main_Panel.getHeight()+50);
    frame.setVisible(true);
    Main_Panel.updateUI();
    static void Out(String message) { System.out.println(message); }
    public static void main(String[] args)
    Exit_When_Window_Closed=true;
    new Java_Test(Software_Info_Chinese_Text).Show_Up();
    final Java_Test demo=new Java_Test(Software_Info_Chinese_Text);
    Dimension Screen_Size=Toolkit.getDefaultToolkit().getScreenSize();
    final JFrame frame=new JFrame("Java Test");
    frame.add(demo);
    frame.addWindowListener(new WindowAdapter()
    public void windowClosing(WindowEvent e) { System.exit(0); }
    public void windowDeiconified(WindowEvent e) { demo.repaint(); }
    public void windowGainedFocus(WindowEvent e) { demo.repaint(); }
    public void windowOpening(WindowEvent e) { demo.repaint(); }
    public void windowResized(WindowEvent e) { demo.repaint(); }
    public void windowStateChanged(WindowEvent e) { demo.repaint(); }
    frame.pack();
    frame.setBounds((Screen_Size.width-demo.getWidth())/2,(Screen_Size.height-demo.getHeight())/2-10,demo.getWidth(),demo.getHeight()+38);
    frame.setVisible(true);
    I called this test program from my large program, and it won't display correctly, it will only display all sizes of characters correctly if I run the test program by itself.
    I've posted a similar question in Java/Swing but got no answer. So I'm trying it here. The above test program will compile and run, it can display all sizes of html fonts correctly.Which means it's not lacking any fonts. I've even tried the following in my large program :
    dialog.validate();
    dialog.repaint();
    pane.validate();
    pane.repaint();
    pane.updateUI();
    A_Label.validate();
    A_Label.repaint();
    A_Label.updateUI();
    Still doesn't work, does anyone know why and how to fix it ?
    Frank                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    I've just made a breakthrough, the large program will work correctly if I comment out : A_Non_English_Label.setFont(Times_New_Roman_15_Font);
    But then the font doesn't look the way I wanted it to be.
    So I changed it to the following :
    ================================================
    Font Courier_New_15_Font=new Font("Courier New",0,15);
    A_Non_English_Label.setFont(Courier_New_15_Font);
    ================================================
    Now it looks not the same but similar to the way I wanted. Thus my question becomes : why it can't work correctly with "Times_New_Roman", but with "Courier_New" in the large program, they both displayed correctly in my small test program ? Is it because it takes too much resource to load the "Times_New_Roman" font ?
    Frank

  • Printing Chinese characters

    Hello all,
    I have been wriiten a program that prints styled Chinese characters,
    using TextLayout class. The strokes are incorrect, some shorter, some longer.
    The TextLayout firstly layout the text and attributes with specified width
    and height (in case word wrapping is needed), then when printing , the Graphics
    object pass into the textLayout.draw method to print the text. I found that
    there is no problem when rendering on screen, and also print using drawString
    method. Is anyone know how to solve this problem? thanks in advance. Here is
    the standalone testing program.
    Jason
    import java.text.*;
    import java.util.*;
    import java.awt.*;
    import java.awt.font.*;
    import java.awt.event.*;
    import java.awt.print.*;
    import java.awt.image.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.text.*;
    public class Test extends JFrame {
    public static void main(String[] args) {
    Locale.setDefault(Locale.CHINESE);
    Test test = new Test();
    test.setVisible(true);
    PrinterJob job;
    PageFormat pageFormat;
    DrawingPanel drawingPanel = new DrawingPanel();
    JPanel buttonPanel = new JPanel();
    JButton printButton = new JButton("Print");
    Test() {
    super("Test");
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    drawingPanel.setPreferredSize(new Dimension(500, 400));
    getContentPane().add(drawingPanel, BorderLayout.CENTER);
    printButton.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent ae) {
    job = PrinterJob.getPrinterJob();
    pageFormat = job.defaultPage();
    job.setPrintable(drawingPanel, pageFormat);
    job.setCopies(1);
    if (job.printDialog()) {
    try {
    job.print();
    catch (Exception e) {
    System.out.println("FilePrint : " + e);
    buttonPanel.add(printButton);
    getContentPane().add(buttonPanel, BorderLayout.SOUTH);
    pack();
    class DrawingPanel extends JPanel implements Printable {
    static final String chineseText = "\ufe51\ufe50\ufe55\ufe54\ufe56\ufe57\u300c\u300d\u3002\u3010\u3011\u3014\u3015\u4e0d\u662f\u516c\u6709\u7684; \u4e0d\u80fd\u88ab\u5916\u90e8\u5305";
    DefaultStyledDocument document = new DefaultStyledDocument();
    String text = chineseText;
    Vector textVector;
    Vector attrStrVector;
    int x = 0;
    int y = 0;
    int width = 400;
    int height = 400;
    int lineSpacing = 5;
    Color textColor = Color.black;
    DrawingPanel() {
    super(false);
    try {
    SimpleAttributeSet attrSet1 = new SimpleAttributeSet();
    document.insertString(0, chineseText, attrSet1);
    catch (BadLocationException ble) {
    public void draw(Graphics2D g,int x,int y) {
    Vector cache = layout(g);
    textDraw(g, cache, x, y);
    private void textDraw(Graphics2D g2d,Vector cache,int offsetX,int offsetY) {
    int accHeight = 0;
    for (int i=0; i < cache.size(); i++) {
    TextLayout textLayout = (TextLayout)cache.elementAt(i);
    accHeight += textLayout.getAscent();
    g2d.setColor(textColor);
    textLayout.draw(g2d, offsetX + x + 1,
    offsetY + y + 1 + accHeight);
    accHeight += (textLayout.getDescent() + (textLayout.getLeading() * lineSpacing));
    textVector.clear();
    attrStrVector.clear();
    public void paint(Graphics _g) {
    Graphics2D g = (Graphics2D) _g;
    g.setColor(Color.white);
    g.fillRect(0, 0, getWidth(), getHeight());
    draw(g, 10, 10);
    g.dispose();
    public int print(Graphics _g, PageFormat pageFormat, int pageIndex) throws PrinterException {
    if (pageIndex >= 1) {
    _g.dispose();
    return Printable.NO_SUCH_PAGE;
    RepaintManager.currentManager(this).setDoubleBufferingEnabled(false);
    Graphics2D g = (Graphics2D) _g;
    g.setColor(Color.white);
    g.fillRect(0,
    0,
    (int)pageFormat.getWidth(),
    (int)pageFormat.getHeight());
    int newOffsetX = 0;
    int newOffsetY = (int)(pageFormat.getImageableHeight() * pageIndex);
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
    RenderingHints.VALUE_ANTIALIAS_ON);
    g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
    RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    g.setClip((int) pageFormat.getImageableX(),
    (int) pageFormat.getImageableY(),
    (int) (pageFormat.getImageableWidth()),
    (int) (pageFormat.getImageableHeight()));
    draw(g,
    (int)(x - newOffsetX + pageFormat.getImageableX()),
    (int)(y - newOffsetY + pageFormat.getImageableY()));
    RepaintManager.currentManager(this).setDoubleBufferingEnabled(true);
    g.dispose();
    return Printable.PAGE_EXISTS;
    private Vector layout(Graphics2D g) {
    Vector cache = new Vector();
    float accHeight = 0;
    TextFormatting formatting = new TextFormatting(document, text);
    textVector = formatting.getTextVector();
    attrStrVector = formatting.getAttrStrVector();
    for (int j = 0; j < attrStrVector.size(); j++) {
    String text = (String)textVector.elementAt(j);
    if (text.length() == 0) {
    AttributedString spaceAs = new AttributedString(" ");
    AttributedCharacterIterator spaceAci = spaceAs.getIterator();
    FontRenderContext spaceFrc = g.getFontRenderContext();
    TextLayout spaceTl = new TextLayout(spaceAci,spaceFrc);
    float spaceHeight = spaceTl.getAscent() + spaceTl.getDescent() + spaceTl.getLeading();
    accHeight += spaceHeight;
    cache.addElement(spaceTl);
    continue;
    AttributedString as = (AttributedString)attrStrVector.elementAt(j);
    FontRenderContext frc = g.getFontRenderContext();
    AttributedCharacterIterator aci = as.getIterator();
    LineBreakMeasurer lbm = new LineBreakMeasurer(aci,frc);
    lbm.setPosition(0);
    int i = 0;
    while (true) {
    TextLayout textLayout = lbm.nextLayout(width - 2);
    if (textLayout == null)
    break;
    accHeight += (textLayout.getAscent() + textLayout.getDescent());
    if (accHeight > height - 2)
    break;
    cache.addElement(textLayout);
    accHeight += (textLayout.getLeading() * lineSpacing);
    return cache;
    class TextFormatting {
    DefaultStyledDocument document;
    String text;
    Vector textVector = new Vector();
    Vector attrStrVector = new Vector();
    TextFormatting(DefaultStyledDocument document, String text) {
    this.document = document;
    this.text = text;
    format();
    private void format() {
    boolean quit = false;
    int index = 0, increment = 1;
    int nextIndex;
    int textIndex = 0;
    String subText;
    if (text.indexOf("\r\n") != -1)
    increment = 2;
    while (!quit) {
    if (increment == 2)
    nextIndex = text.indexOf("\r\n",index);
    else
    nextIndex = text.indexOf("\n",index);
    if (nextIndex == -1) {
    subText = text.substring(index);
    quit = true;
    else {
    subText = text.substring(index,nextIndex);
    textVector.addElement(subText);
    AttributedString as = new AttributedString(subText);
    for (int i = 0; i < subText.length(); i++) {
    Element ele = document.getCharacterElement(textIndex++);
    AttributeSet attrSet = ele.getAttributes();
    Font f = document.getFont(attrSet);
    as.addAttribute(TextAttribute.FONT, f, i, i + 1);
    if (StyleConstants.isUnderline(attrSet)) {
    as.addAttribute(TextAttribute.UNDERLINE,
    TextAttribute.UNDERLINE_ON,
    i,
    i + 1);
    attrStrVector.addElement(as);
    index = nextIndex + increment;
    textIndex++;
    public Vector getTextVector() {
    return this.textVector;
    public Vector getAttrStrVector() {
    return this.attrStrVector;

    Amending the above question:
    I am using Window 98 Taiwan Edition, JDK1.3.1 international, and I have set locale to TW (Taiwan)
    Jason

  • Displaying Chinese Characters in a JLabel

    I wish to display Chinese characters in a JLabel WITHOUT setting the JLabel's font. The following code works fine under Java 1.4.x for Mac OSX, and Java 1.5 for Windows. However, the characters do NOT display properly under Java 1.4.x for Windows. Does anyone have any idea why? I really need to get this to work under 1.4.x for Windows without having to call JLabel.setFont(...). Maybe it's a known bug in 1.4.x that has a workaround (hopefully)?
            javax.swing.JFrame frame = new javax.swing.JFrame("Chinese Test");
            JLabel label = new javax.swing.JLabel("\u54C8\u7F57", javax.swing.JLabel.CENTER);
            frame.getContentPane().add(label, java.awt.BorderLayout.CENTER);
            frame.getContentPane().setSize(200, 200);
            frame.setLocation(50, 50);
            frame.setSize(200, 200);
            frame.setVisible(true);

    1. I do not wish to set the Font on the label(s) because we have localized our application in many languages using a custom localization scheme and I do not want to change all of the code.
    2. Yes, I have all the forms of Chinese installed on my Windows system.
    3. I found that if I use an HTML string of the form: <html><body><font face="SimSun">\unicode chinese chars...
    then THAT WORKS. The JLabel renders the String in Chinese. This might be a good option for us.
    4. All of it works automatically without the need for an HTML String under Java 1.5 because evidently 1.5 has built-in support for setting the proper font on the widget after analyzing the unicode characters.
    - Eric

  • Displaying UTF chinese characters

    Here's my code
              final StringBuilder sb = new StringBuilder();
              DropWindow dw = new DropWindow() {
                   public void runFile(File f, Object[] extras) {
                        try {
                             String str = IOUtils.readFileAsString(f);
                             for (int i = 0; i < str.length(); i++) {
                                  System.out.println("char[" + i + " ] = " + (int)str.charAt(i));
                             sb.append(str);
                        catch (IOException iox) {
                             iox.printStackTrace();
              JPanel jp = new JPanel() {
                   public void paintComponent(Graphics g) {
                        super.paintComponent(g);
                        g.drawString(sb.toString(), getWidth() / 2, getHeight() / 2);
              dw.add(jp);
              WindowUtilities.visualize(dw);when I run this I get
    char[0 ] = 20320
    char[1 ] = 22909
    char[2 ] = 13
    char[3 ] = 10
    in the command line. On the screen I get 2 squares where I'm hoping my chinese characters will be.
    Is it just that I'm not using an international version of java? I just went to the download page and it seems like all java versions are international now. Could it be that my font can't represent the characters?
    How can I paint chinese characters?

    I don't understand. 'Arial' will never display Chinese. In JRE1.6, the only font I know that displays Chinese is "AR PL ShanHeiSun Uni". In 1.5 there was a second one but that seems to have been removed.
    When I want to find a font for a particular character set I use the following simple Swing application -
    import java.awt.BorderLayout;
    import java.awt.Font;
    import java.awt.GraphicsEnvironment;
    import java.awt.GridLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.util.ArrayList;
    import java.util.Iterator;
    import javax.swing.BorderFactory;
    import javax.swing.JCheckBox;
    import javax.swing.JComboBox;
    import javax.swing.JComponent;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JList;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.ListSelectionModel;
    import javax.swing.UIManager;
    import javax.swing.event.ListSelectionEvent;
    import javax.swing.event.ListSelectionListener;
    public class FontAndCharDisplay extends JFrame
        private JComponent createStyleSelector()
            JPanel panel = new JPanel();
            panel.add(boldButton);
            panel.add(italicButton);
            ActionListener styleListener = new ActionListener()
                public void actionPerformed(ActionEvent event)
                    updateDisplayOfChars();
            boldButton.addActionListener(styleListener);
            italicButton.addActionListener(styleListener);
            panel.setBorder(BorderFactory.createTitledBorder("Style"));
            return panel;
        private JComponent createSizeSelector()
            int[] sizes =
            {8,9,10,11,12,14,16,18,20,24,28,32, 36, 40, 48, 56, 64, 72, 84,100};
            final JComboBox sizeSelector = new JComboBox();
            for (int index = 0; index < sizes.length; index++)
                sizeSelector.addItem(new Integer(sizes[index]));
            fontSize = 14;
            sizeSelector.setSelectedItem(new Integer(fontSize));
            sizeSelector.addActionListener(new ActionListener()
                public void actionPerformed(ActionEvent event)
                    fontSize = ((Integer)sizeSelector.getSelectedItem()).intValue();
                    updateDisplayOfChars();
            sizeSelector.setBorder(BorderFactory.createTitledBorder("Size"));
            sizeSelector.setOpaque(false);
            return sizeSelector;
        private JComponent createPageSelector()
            String[] pageAddresses = new String[256];
            for (int row = 0; row < 16; row++)
                for (int col = 0; col < 16; col++)
                    pageAddresses[row*16+col] = HEX_CHARS[row] + (HEX_CHARS[col] + "00");
            final JComboBox addressSelector = new JComboBox(pageAddresses);
            addressSelector.addActionListener(new ActionListener()
                public void actionPerformed(ActionEvent event)
                    updateAddressBase(Integer.parseInt((String)addressSelector.getSelectedItem(), 16));
            addressSelector.setBorder(BorderFactory.createTitledBorder("Page"));
            addressSelector.setOpaque(false);
            return addressSelector;
        private FontAndCharDisplay()
            super("Font Display");
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            JPanel upperPanel = new JPanel(new BorderLayout());
            JPanel controlsPanel = new JPanel(new GridLayout(1,0));
            controlsPanel.add(createPageSelector());
            controlsPanel.add(createSizeSelector());
            controlsPanel.add(createStyleSelector());
            upperPanel.add(controlsPanel, BorderLayout.NORTH);
            fontSelector = new JList(GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames());
            fontSelector.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            fontSelector.addListSelectionListener(new ListSelectionListener()
                public void valueChanged(ListSelectionEvent e)
                    if (!e.getValueIsAdjusting())
                        updateDisplayOfChars();
            JScrollPane fontNameDisplay = new JScrollPane(fontSelector);
            fontNameDisplay.setBorder(BorderFactory.createTitledBorder("Name"));
            upperPanel.add(fontNameDisplay, BorderLayout.CENTER);
            fontSelector.setSelectedIndex(0);
            getContentPane().add(upperPanel, BorderLayout.NORTH);
            // Build the set of components to display the characters
            for (int index = 0; index < 256; index++)
                charDisplayFields.add(new JLabel(""));
            // Build the main character display area
            int startPoint = 0;
            final JPanel charDisplayPanel = new JPanel(new GridLayout(0, 17));
            charDisplayPanel.add(new JLabel(""));
            for (int col = 0; col < 16; col++)
                charDisplayPanel.add(new JLabel(Character.toString(HEX_CHARS[col])));
            for (int row = 0; row < 16; row++)
                charDisplayPanel.add(new JLabel(Character.toString(HEX_CHARS[row])));
                for (int col = 0; col < 16; col++)
                    charDisplayPanel.add((JComponent)charDisplayFields.get(startPoint++));
            JScrollPane characterDisplay = new JScrollPane(charDisplayPanel);
            characterDisplay.setBorder(BorderFactory.createTitledBorder("Page Display"));
            getContentPane().add(characterDisplay, BorderLayout.CENTER);
            updateAddressBase(0);
            updateDisplayOfChars();
            pack();
        private void updateAddressBase(int start)
            for (Iterator it = charDisplayFields.iterator(); it.hasNext();)
                JLabel label = (JLabel)it.next();
                label.setText(Character.toString((char)start++));
        private void updateDisplayOfChars()
            // Calculate the style
            int style = 0;
            if (italicButton.isSelected())
                style |= Font.ITALIC;
            if (boldButton.isSelected())
                style |= Font.BOLD;
            // Build the font
            Font font = new Font((String)fontSelector.getSelectedValue(), style, fontSize);
            System.out.println(font);
            // Update all the char labels to use the new font
            for (Iterator it = charDisplayFields.iterator(); it.hasNext();)
                JLabel label = (JLabel)it.next();
                label.setFont(font);
        public static void main(String[] args)
            try
                UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                new FontAndCharDisplay().setVisible(true);
            catch (Exception e)
                e.printStackTrace();
        private int fontSize = 10;
        private ArrayList charDisplayFields = new ArrayList(256);
        private JCheckBox boldButton = new JCheckBox("Bold");
        private JCheckBox italicButton = new JCheckBox("Italic");
        private JList fontSelector;
        private static final char[] HEX_CHARS =
        {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
    }Please don't look too close at the code - it was one of my earliest Swing applications.
    P.S. These values
    char[2 ] = 13
    char[3 ] = 10
    are just CR and LF and not Chinese.
    Edited by: sabre150 on Aug 29, 2008 9:21 PM

  • How display chinese characters?

    Hi all,
         I want to display chinese characters in JTextPane/JTextField. I code a small program to try but can't get the correct result. The following is my program.
    import javax.swing.*;
    import java.util.*;
    import java.io.*;
    import java.awt.*;
    public class TestBig5 extends JFrame {
         public TestBig5() {          
              String str = readInput();     
              JTextField tp = new JTextField();
              tp.setFont(new Font("Kai (big5.eten.3.10-1)",Font.PLAIN,16));
              tp.setLocale(Locale.TAIWAN);
              tp.setText(str);
              getContentPane().add(tp);
              pack();          
              setVisible(true);          
    static String readInput() {
    StringBuffer buffer = new StringBuffer();
    try {
    FileInputStream fis = new FileInputStream("testbig5.txt");
    InputStreamReader isr = new InputStreamReader(fis, "Big5");
    Reader in = new BufferedReader(isr);
    int ch;
    while ((ch = in.read()) > -1) {
    buffer.append((char)ch);
    in.close();
    return buffer.toString();
    } catch (IOException e) {
    e.printStackTrace();
    return null;
         static public void main(String args[]) {
              new TestBig5();
    The problem is that the JTextField only shows blank space.
    testbig5.txt is a text file that contains big5 encoding characters.
    "Kai (big5.eten.3.10-1)" is the only chinese font in my system, and I can use it to display chinese characters in netscape. And the file testbig5.txt can also be displayed in netscape correctly.
    I have also tried to use font.properties.zh_TW_Big5 but still no success.
    please advise what should I do so that the problem can be fixed. And following is my system config.
    Sco unix 5.0.5
    JDK 1.2.2
    Thanks in advance.
    Anson

    (1) First of all use FileReader and not inputstreams. The diff. is that streams are not unicode compliant whereas readers are.
    (2) Similary use only generic fonts.For example, this prints fine for me
    jTextField1.setFont(new java.awt.Font("Serif", 0, 12));
    jTextField1.setText("Serif \u65e5\u672c\u8a9e");
    [email protected]
    HP

  • Can only display Chineses characters on OSX, not Windows Vista ?

    I have a OSX 10.5 and a Windows Vista machine, both are configured to use English/United Kingdom as Language/Locale. in a java app on OSX I can view chinese characters ok, but on Windows I cant they are just displayed as a square - why are they being treated differently
    thanks paul

    Thanks, that did work - I used this.setFont(Font.decode("arial unicode 11"));
    But on further investigation I found that the problem only occurred with the default Tahoma font when using JGoodies Windows Look and Feel, using the standard Windows or metal LAF it was fine. If I changed the font it worked with JGoodies as well.
    here is a program to illustrate problem
    import javax.swing.*;
    import java.awt.*;
    public class UnicodeTest
        public void start() throws Exception
           UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
           UIManager.setLookAndFeel("com.jgoodies.looks.windows.WindowsLookAndFeel");
            JTextField txtField = new JTextField();
            txtField.setText("\u01ff\u5742\u672c");
            JTextField txt2Field = new JTextField();
            txt2Field.setText("\u01ff\u5742\u672c");
            txt2Field.setFont(Font.decode("arial unicode 11"));
            System.out.println("Font Field 1 is:"+txtField.getFont());
            System.out.println("Font Field 2 is:"+txt2Field.getFont());
            JFrame frame = new JFrame("UnicodeTest");
            frame.setLayout(new FlowLayout());
            frame.add(txtField);
            frame.add(txt2Field);
            frame.pack();
            frame.setVisible(true);
         public static void main(String args[])  throws Exception
            UnicodeTest test = new UnicodeTest();
            test.start();
    }

  • How to configure my Firefox thus allowing me to input Chinese characters into the search box by using PenPower writing pad while this problem doesn't exist when I am using Internet Explorer?

    I am using the electronic writing pad made by PENPOWER Inc. to input Chinese characters onto my PC programs (e.g. Winword, Internet Explorer, Excel, etc.) But I can not make it happened on Firefox, please advice what I have to do with the configuration of the Firefox or using any other method to make it work. Thanking you guys in advance for helping me to solve this problem.

    cor-el,
    Thank you very much for your advice. The new software of Penpower works rightaway after I installed it on my pc. Thanks again.
    十分感激你的幫忙!

  • Arabic and Chinese characters are showing ??? in PDF

    Hi
    I hava an application which calls BI publisher API to generate PDF file from rtf temlate and xml input. It is fine for English contents. But the Arabic or Chinese characters are showing ??? in PDF. If I use BI publisher Desktop to load the xml and generate pdf file, it shows correct Arabic/Chinese Characters in PDF. I also copied ALBANWTJ.ttf file to my application JAVA_HOME/jre/lib/fonts/ folder. But it still doesn't work. Anyone can help me with this?
    Thanks a lot!

    I created xdo.cfg and put it in my JAVA_HOME/jre/lib/ folder. the file is configured as below:
    <?xml version="1.0" encoding="UTF-8"?>
    <config version="1.0.0" xmlns="http://xmlns.oracle.com/oxp/config/">
    <properties>
    <property name="system-temp-dir">/tmp</property>
    </properties>
    <fonts>
    <font family="Default" style="normal" weight="normal">
    <truetype path="/fonts/ALBANWTJ.ttf"/>
    </font>
    </fonts>
    </config>
    But now I'm getting this error while generating pdf file:
    Adobe Reader could not open 'xxx.pdf' because it is either not a supported file type or because the file has been damaged (for example, it was sent as an email attachment and wasn't correctly decoded).
    Is there anything wrong in my xdo.cfg?
    Thanks!

  • Chinese characters are not displayed in the Firefox bookmarks

    Chinese characters are not displayed in the Firefox bookmarks. The name looks like e.g. "??????? ???? cn.nytimes.com"
    Chinese character of the site name is displayed ok in the head of the browser window and there is no problem reading chinese web content. I use Firefox Portable 11 /English from portableapps.com in Windows XP.
    I googled and got some tips:
    1) Set your browser to recognise Chinese language internet sites.
    Windows users: Under "Tools - Options" on your browser's menu-bar add Chinese to the languages list.
    - I did this.
    2) Set your browser's "Character Set" or "Encoding" to UTF-8 (sometimes also called Universal Alphabet or Unicode).
    Encoding settings can be changed under the "View" option in your browser's menu-bar.
    - It was already set to UTF-8.
    3) Windows users: If Chinese text still does not display correctly, East Asian language support may need to be enabled.
    - This has been done when I installed Windows.
    I still don't get any Chinese fonts in the bookmark names. I can edit the bookmark name with chinese characters and then save the bookmark, it works fine. But why does not Firefox recognize the characters when saving bookmarks? Help is appreciated.

    No I didn't change anything deep beneath the hood. My problem didn't apply to the URL, but to the name of the link or bookmark header or whatever you would like to call it. (When hitting Ctrl + D there is a Name field). I only got ???????? instead of chinese characters in the name. Also for e.g. www.cntv.cn ...but maybe all China is not in the whitelist either. ;-) But anyway, this was not the real problem for me.
    Apparently I was wrong as after a reboot of the computer it worked. The solution seemed to be to add Chinese to the language list. I don't know why it was not enough to restart Firefox?
    Now I only have problems to show chinese characters in the name field of my external link manager... But I guess it is not an issue for Mozilla.

  • Chinese characters scrambled when loading from DS to BW

    Hi, I've been pulling my hair out with this issue.
    I have a flat file containing Chinese text. When I load this in BW using 'FLATFILE' as a source system, it works fine. BW shows the correct Chinese characters.
    When I do the same load using BODI, I get funny characters.
    When I use BODI to load from one flat file into another flat file, the Chinese characters remain correct.
    What do I need to do to make sure I get the right Chinese characters in BW when loading from BODI?
    BODI is installed on Unix on Oracle 10.
    I run the jobs as batch processes.
    The dsconfig.txt has got:
    AL_Engine=<default>_<default>.<default>
    There are no locale settings in al_env.sh
    BW target is UTF-8 codepage.
    File codepage is BIG5-HKSCS
    BODI is set up as a Unicode system in SAP BW.
    When loading flat file to flat file, I get a message:
    DATAFLOW: The specified locale <eng_gb.iso-8859-1> has been coerced to <Unicode (UTF-16)
    because the datastore <TWIN_FF_CUSTOMER_LOCAL> obtains data in <BIG5-HKSCS> codepage.
    JOB: Initializing transcoder for datastore <TWIN_FF_CUSTOMER_LOCAL> to transcode between
    engine codepage<Unicode (UTF-16)>  and datastore codepage <BIG5-HKSCS>
    When loading to BW the messages are almost the same, but now the last step in UTF-16 to UTF-8.
    I read the wiki post which definitely helped me to understand the rationale behind code page, but now I ran out of ideas what else to check ( http://wiki.sdn.sap.com/wiki/display/BOBJ/Multiple+Codepages )
    Any help would be greatly appreciated.
    Jan.

    Hi all. Thanks for the Inputs. This is what I got when I clicked on the Details Tab of the Monitor....
    Error when transferring data; communication error when analyzing
    Diagnosis
    Data packages or InfoPackages are missing in BI but there were no apparent processing errors in the source system. It is therefore probable that there was an error in the data transfer.
    The analysis tried to read the ALE outbox of the source system. This lead to error .
    It is possible that there is no connection to the source system.
    Procedure
    Check the TRFC overview in the source system.
    Check the connection to the source system for errors and check the authorizations and profiles of the remote user in both the BI and source systems.
    Check th ALE outbox of the source system for IDocs that have not been updated.

  • Report Generation Toolkit using Chinese Characters

    I am trying to use the Report Generation Toolkit for Microsoft Office under LabVIEW 8.0.  I would like to use Chinese characters for the headings of the columns using a 2D array of the headings and the Excel Easy Table.  When I generate the report, the text of the headings appears to be jumbled and not encoding correctly.
    For example:
    仪器编号 becomes êNhV÷S
    采前初重(g) becomes Ç‘MRRÍ‘ÿg
    Any insights here? Thanks

    Hi,
    what you describe reminded me of a bug fix in the Report Generation Toolkit 2012 :
    339092
    Using the "Append Table to Report" VI to add strings of Cyrillic font to a table in an MS Word report results in gibberish being added to the report.
    http://digital.ni.com/public.nsf/allkb/09D6DE5170B3C0BD86257A2B004CFD20
    I know that Cyrillic and Chinese characters are different but they are often confronted to the same problems...
    Aurelie

  • How can I force text in a table to wrap at the margin? Chinese characters result in wide tables.

    Hello all ye RoboHelpers out there.
    Background:
    We're using RH 9 (latest patch) on Windows 7 machine.
    We document in English and then the RH project gets localized into many diff languages and we use that to generate CHM, and Printed outputs.
    The Problem:
    In the Chinese language, in printed output, the right border of most tables exeeds well beyond the margin.
    Here's what the localized table looks like in the RH editor:
    By comparison, here's the equivalent English topic prior to localization:
    Our CHM output is fine. In fact, here's what the Chinese looks like in when output to a browser or previewed and I drag the right side to
    a narrower width. Notice that the table text appropriately wraps to remain within the window's size:
    But here's what it looks like when I generate it in Word's printed output:
    Notice the location of the margin at 6.5 inches. It should be wrapping at the margin. And something is weird with the left cell how it's getting pushed so far to the right.
    The actual table width ends up around 11 inches! I had some tables last time I did this that were as far out as 18 inches but looked perfectly fine in English!
    We use Across Systems for our localization tool, and I've verified that our translators are not messing with the table properties at all; only the text is exposed. One interesting difference I've noticed from other languages, is that Chinese characters do not contain a true space or period characters when we get them back from localization. This makes sentences essentially a really long string of unbroken characters, and I suspect this somehow pushes the generated tables to wide extremes in printed output.
    What I've Tried:
    I've tried to change the table properties in Word to auto fit the size of the window.
    I've tried setting the width in RH to a specific size and regenerating. Still doesn't help.
    I've added in space character and doing that does cause lines to wrap in some cases, but not in all. But I shouldn't have to do this.
    I've tried to create a VBA macro in Word to size the tables, but couldn't get it to work.
    What I need:
    I need to somehow globally force all the tables' text strings to wrap once they reaches the right margin no mater what, even if the line does not contain space characters. Is there a setting I'm missing somewhere, either on the RH side or the Word side that can do this for these long strings of characters?
    I really hope someone else has figured out how to deal with this because last time I did this, I had to go through approximately 500 tables and manually do a very convoluted workaround dragging the table handle in Print layout mode back to the right margin to get the table to wrap appropriately. It was a major pain in neck!
    Many thanks in a advance for any ideas you might have.

    I wonder the Format Tables macros on my site could be adapted?
    http://www.grainge.org/pages/authoring/word/word_macros.htm
    If not, I have used Macro Express to format tables in Rh. No reason it could not be used in Word.
    See www.grainge.org for RoboHelp and Authoring tips
    @petergrainge

Maybe you are looking for