Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 4335102
Votes 4
Synopsis Can't display chinese correctly in JOptionPane under JDK1.3
Category java:classes_swing
Reported Against 1.3 , kestrel-rc3
Release Fixed
State 11-Closed, duplicate of 4339627, bug
Priority: 4-Low
Related Bugs 4339627
Submit Date 02-MAY-2000
Description




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) 
======================================================================




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)
======================================================================




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)
======================================================================




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)
======================================================================
Work Around
N/A
Evaluation
The bulk of this bug is a duplicate of 4339627. However, I'm not closing this bug since it's on our top 50 bug list, which is relevant in deciding how to address the problem (update or maintenance release).
  xxxxx@xxxxx   2000-07-26


[  xxxxx@xxxxx   2000-09-27]
The fix (resource bundle's rename) & workaround (font.properties.zh_TW's 
workaround) have already been in firefly, and I have verified the problems
are gone. So mark this bug as "INT" for firefly.
Comments
  
  Include a link with my name & email   

Submitted On 12-MAY-2000
armstrng
I've also found the error message output by javac in 
J2SEv1.3 to be corrupted - question marks appear in place 
of some Chinese characters. Also the message is hard to 
understand - I learn Java from English books. Can I change 
that back to English?


Submitted On 14-MAY-2000
armstrng
I found something strange...

About compiler's Chinese error message, that only happens 
when I use C:\Jdk1.3\bin\javac, that is, when I specify 
explicitly where javac is. If I type &quot;javac&quot; only, it will 
use the v1.3 javac, and error messages are in English.

That's very strange.


Submitted On 19-MAY-2000
ericyfm
It seems that j2se uses the simplified chinese characters 
only. Even the Locale is zh_TW, it still use the simplified 
chinese characters settings.


Submitted On 08-JUN-2000
carfield
I think that display the error in English is better as all 
the code is English base



PLEASE NOTE: JDK6 is formerly known as Project Mustang