Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4335102

Can't display chinese correctly in JOptionPane under JDK1.3

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.3.0
    • client-libs
    • x86
    • windows_98, windows_nt



      Name: rlT66838 Date: 05/02/2000


      java version "1.3.0rc3"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0r3-Z)
      Java HotSpot(TM) Client VM (build 1.3.0rc3-Z, mixed mode)

        From the program below, I can display the Chinese characters when I set the
      fonts for each label components. However, the JOptionPane does not allowed me
      to set the fonts so that the Chinese characters cannot display correctly.

      1. javac Sample.java (The program listed below)
      2. java Sample
      3. type in the username and password, then press the button
      4. The chinese characters in JOptionPane will be displayed with distortion

      The following is the codes of Sample.java
      _______________________________________________________________________________
      import javax.swing.*;
      import java.awt.*;
      import java.awt.event.*;
      import java.io.*;

      public class Sample {

          JTextField textField = null;
          JPasswordField passwordField = null;

          public static void main(String[] argv) {
             new Sample();
          }

          Sample() {
      // spwan a timer thread

      textField = new JTextField(18);
      Font font = new Font("Dialog", Font.PLAIN, 12);
      JLabel label1 = new JLabel("輸入用戶名稱 (例:hgc12345)");
      label1.setFont(font);
      textField.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
      }
      });

      final JFrame f = new JFrame("核對用戶身份");
      Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
      f.setBounds ( 250, 250, screenSize.width - 300*2,
      screenSize.height - 300*2 );

      JLabel label2 = new JLabel("輸入用戶密碼 (例:P123456A)");
      label2.setFont(font);
      passwordField = new JPasswordField(18);
      passwordField.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {

      }
      });

      JButton button = new JButton("確定");
      button.setFont(font);

      button.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
      }
      });
      JPanel labelPane = new JPanel();
      labelPane.setLayout(new BoxLayout(labelPane,BoxLayout.Y_AXIS));
      labelPane.add(Box.createRigidArea(new Dimension(0, 3)));
      labelPane.add(label1);
      labelPane.add(Box.createRigidArea(new Dimension(0, 7)));
      labelPane.add(label2);

      JPanel fieldPane = new JPanel();
      fieldPane.setLayout(new BoxLayout(fieldPane,BoxLayout.Y_AXIS));
      fieldPane.add(textField);
      fieldPane.add(Box.createRigidArea(new Dimension(0, 5)));
      fieldPane.add(passwordField);

      JPanel buttonPane = new JPanel();
      buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.X_AXIS));
      buttonPane.setBorder(BorderFactory.createEmptyBorder(10, 0, 0,
      0));
      buttonPane.add(Box.createHorizontalGlue());
      buttonPane.add(button);

      JPanel contentPane = new JPanel();
      contentPane.setBorder(BorderFactory.createEmptyBorder(10,10, 10, 10));
      contentPane.setLayout(new BorderLayout());
      contentPane.add(labelPane, BorderLayout.WEST);
      contentPane.add(fieldPane, BorderLayout.CENTER);
      contentPane.add(buttonPane, BorderLayout.SOUTH);

      f.setContentPane(contentPane);
      f.pack();
      f.setVisible(true);

          }

      }
      (Review ID: 104016)
      ======================================================================

      Name: rlT66838 Date: 05/19/2000


      I have uninstalled the Java 2 SDK SE 1.3 and use Java 2 SDK SE 1.2.2 instead so
      I cannot reproduce this message again.

      I just run the jfc Swingset2 demo in jdk1.3 on Traditional Chinese Windows 98.
      All the Chinese fonts are not properly displayed, so I uninstalled the 1.3
      version and use the 1.2.2 instead. Please make the fonts display properly in
      all platforms or NOT TO MAKE IT INTERNATIONALIZE! Further and frankly speaking,
      I could speak fluent Chinese but I really could not understand the Chinese
      messages generated by the compiler. Please hire a person who has a better
      Chinese background to write the messages. Thanks.
      (Review ID: 105096)
      ======================================================================

      Name: rlT66838 Date: 06/02/2000


      java -1.3

      Running the same code in Win NT 4.0 and Win98,
      the Chinese characters appeared correctly in Win NT 4.0
      but showed up garbled in Win98.

      chinese.setFont(new Font("\u7d30\u660e\u9ad4", Font.PLAIN, 14));
      chinese = new JButton("\u7e41\u9ad4\u4e2d\u6587");
      (Review ID: 105626)
      ======================================================================

      Name: rlT66838 Date: 06/09/2000


      java version "1.3.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
      Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)

      It seems to me that JDK 1.3 have some difficulity when displaying chinese
      character in JLabel and JButton.

      Included is a program which reproduce the bug.

      In the program, I pass in the same Unicode string into Label, JLabel, JButton,
      and JtextField. Apparently, the text displayed in the JtextField and Label are
      all readable. Those in Jlabel and Jbutton, however, are unreadable.

      I also do another experientment by encoding the text into Big 5 and display
      their code. It also show some differents between Jlabel and JtextField.

      Something instresting I found is that it can be display correctly if I use the
      Jlabel.setFont method. But Jlabel and Jbutton seems can’t get the setting in
      the font.properties while JtextField is displaying properly.

      import java.awt.*;
      import java.awt.event.*;
      import javax.swing.*;
      import javax.swing.plaf.*;
      import java.io.*;

      public class ChineseTest
      {
      public static void main(String[] args)
      {
      byte[] big5Bytes = null;
      JLabel l = null;
      Label ml = null;
      String string = new String("ABCD \u7d30\u660e\u9ad4");

      GridBagConstraints gbc = new GridBagConstraints();
      gbc.gridwidth=GridBagConstraints.REMAINDER;

      try
      {
      big5Bytes = string.getBytes("BIG5");
      l = new JLabel(string);
      ml = new Label(string);
      }
      catch(UnsupportedEncodingException e)
      {
      e.getMessage();
      }
      Frame f = new Frame();
      JTextField ltf = new JTextField(l.getText());
      JLabel c = new JLabel("ABCD 細明體");
      JTextField ctf = new JTextField(c.getText());

      /*

      l.setFont(new Font("\u7d30\u660e\u9ad4",Font.PLAIN,12));
      ltfsetFont(new Font("\u7d30\u660e\u9ad4",Font.BOLD,12));
      c.setFont(new Font("\u7d30\u660e\u9ad4",Font.PLAIN,14));
      ctfsetFont(new Font("\u7d30\u660e\u9ad4",Font.PLAIN,14));
      */

      f.setLayout(new GridBagLayout());

      f.add(ml,gbc);
      f.add(l,gbc);
      f.add(new JLabel("Length = "+l.getText().length()),gbc);
      System.out.println("Font used is: "+l.getFont());
      System.out.println("Font in tb is: "+ltf.getFont());
      System.out.println("Value of "+l.getText()+" are: ");
      value(l.getText());
      f.add(ltf,gbc);
      f.add(new JButton(l.getText()),gbc);

      f.add(new JLabel(" "),gbc);

      f.add(c,gbc);
      f.add(new JLabel("Length = "+c.getText().length()),gbc);
      System.out.println("Font used is: "+c.getFont());
      System.out.println("Font in tb is: "+ctf.getFont());
      System.out.println("Value of "+c.getText()+" are: ");
      value(c.getText());
      f.add(ctf,gbc);

      System.out.println(new String(big5Bytes));
      value(big5Bytes);
      f.addWindowListener(new WindowAdapter()
      { public void windowClosing(WindowEvent e)
      {
      System.exit(0);
      }
      });

      f.pack();
      f.setVisible(true);
      }

      private static void value(String s)
      {
      char[] charArray = s.toCharArray();
      for(int i=0;i<charArray.length;i++)
      {
      System.out.println(charArray[i]);
      }
      }

      private static void value(byte[] s)
      {
      for(int i=0;i<s.length;i++)
      {
      System.out.println((char)s[i]);
      }
      }
      }
      (Review ID: 105927)
      ======================================================================

            nlindenbsunw Norbert Lindenberg (Inactive)
            rlewis Roger Lewis (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: