JDK-4103579 : JDK1.2b2(win32) TextArea and TextField do not support non-English
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.1.3,1.1.4,1.2.0
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • OS: solaris_2.5.1,windows_95,windows_nt
  • CPU: x86,sparc
  • Submitted: 1998-01-13
  • Updated: 1999-01-15
  • Resolved: 1999-01-15
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
1.2.0 1.2beta3Fixed
Related Reports
Duplicate :  
Duplicate :  
Relates :  
Relates :  
Relates :  
Relates :  
Description

Name: gvC48267			Date: 01/13/98


In Japanese-Windows95 system,
JDK1.2b2(win32)'s TextArea and TextField cannot display
non-English language strings.

I can input Japanese strings in TextArea and TextField correctly.
And they are displayed correctly.
But Japanese strings (Unicode escaped) in a source program
are not displayed in TextArea and TextField correctly.
Another Components(Button, etc) can be displayed correctly.
BugID 4060931 seems a Solaris bug.
My bug can be evaluated by the same program in the bug report.

My test program is following.

-----ShowUnicode.html-----
<HTML>
<HEAD>
<TITLE>
</TITLE>
</HEAD>
<BODY>
<applet code="ShowUnicode.class" width="500" height="500">
</applet>
<HR>
</BODY>
</HTML>
-----ShowUnicode.java-----
/**
 * 
 * Unicode \u8868\u793a\u30c6\u30b9\u30c8(Unicode)
 * %W% (%E%)
 *
 *
 * @version 	%W% %E%
 * @author 	Toshiki Murata
 *
 * Copyright (C) 1996 Oki Electric Industry Co.,Ltd.
 */
import java.applet.Applet;
import java.awt.*;

public class ShowUnicode extends Applet {

    public void init() {
        Component parent = this;
        while (parent != null && !(parent instanceof Frame)) {
            parent = parent.getParent();
        }
        if (parent != null) {
            MenuBar menubar = ((Frame)parent).getMenuBar();
	    Menu menu1, menu2, menu3 ;
	    menu1 = new Menu("Menu");
	    menu1.add(new MenuItem("Close"));
	    menu2 = new Menu("Kanji(Unicode) --> \u6f22\u5b57");
	    menu2.add(new MenuItem("Kanji(Unicode) --> \u6f22\u5b57"));
	    menu3 = new Menu("Sub Kanji(Unicode) --> \u6f22\u5b57");
	    menu3.add(new MenuItem("Kanji(Unicode) --> \u6f22\u5b57"));
	    menu2.add(menu3);
	    if (menubar != null) {
		menubar.add(menu1);
		menubar.add(menu2);
	    } else {
		menubar = new MenuBar();
		menubar.add(menu1);
		menubar.add(menu2);
		((Frame)parent).setMenuBar(menubar);
	    }
        }

	// \u6f22\u5b57(\ub4c1\ubbfa in Unicode)
	add(new Label("Kanji(Unicode) --> \u6f22\u5b57")) ;
	add(new TextArea("Kanji(Unicode) --> \u6f22\u5b57"));
	//TextArea textArea;
	//add(textArea = new TextArea());
	//textArea.setText("Kanji(Unicode) --> \u6f22\u5b57");
	add(new TextField("Kanji(Unicode) --> \u6f22\u5b57"));
	add(new Button("Kanji(Unicode) --> \u6f22\u5b57"));
	add(new Checkbox("Kanji(Unicode) --> \u6f22\u5b57"));

	List list;
	list = new List();
	list.addItem("Kanji(Unicode) --> \u6f22\u5b57");
	list.addItem("Kanji(Unicode) --> \u6f22\u5b57");
	list.addItem("Kanji(Unicode) --> \u6f22\u5b57");
	add(list);

	Choice chooser = new Choice();
	chooser.add("Kanji(Unicode) --> \u6f22\u5b57");
	chooser.add("Kanji(Unicode) --> \u6f22\u5b57");
	chooser.add("Kanji(Unicode) --> \u6f22\u5b57");
	add(chooser);

	Canvas canvas = new ShowUnicodeCanvas("Kanji(Unicode) --> 
\u6f22\u5b57");
	canvas.setForeground(Color.red);
	canvas.setBackground(Color.white);

	add(canvas);

	Frame frame = new ShowUnicodeFrame(this);
    }

    public static void main(String[] args) {
	Frame frame = new Frame();
	frame.resize(500,500);
	ShowUnicode showUnicode = new ShowUnicode();
	frame.add(showUnicode);
	frame.show();
	showUnicode.init();
	showUnicode.start();
    }
}

class ShowUnicodeFrame extends Frame {
    Applet applet;
    ShowUnicodeFrame(Applet applet) {
	super("Kanji(Unicode) --> \u6f22\u5b57");

	this.applet = applet;

	setLayout(new FlowLayout());

	Menu menu1, menu2, menu3 ;
	menu1 = new Menu("Menu");
	menu1.add(new MenuItem("Close"));
	menu2 = new Menu("Kanji(Unicode) --> \u6f22\u5b57");
	menu2.add(new MenuItem("Kanji(Unicode) --> \u6f22\u5b57"));
	menu3 = new Menu("Sub Kanji(Unicode) --> \u6f22\u5b57");
	menu3.add(new MenuItem("Kanji(Unicode) --> \u6f22\u5b57"));
	menu2.add(menu3);
	MenuBar mbar = new MenuBar();
	mbar.add(menu1);
	mbar.add(menu2);
	setMenuBar(mbar);

	// \u6f22\u5b57(\ub4c1\ubbfa in Unicode)
	add(new Label("Kanji(Unicode) --> \u6f22\u5b57")) ;
	add(new TextArea("Kanji(Unicode) --> \u6f22\u5b57"));
	//TextArea textArea;
	//add(textArea = new TextArea());
	//textArea.setText("Kanji(Unicode) --> \u6f22\u5b57");
	add(new TextField("Kanji(Unicode) --> \u6f22\u5b57"));
	add(new Button("Kanji(Unicode) --> \u6f22\u5b57"));
	add(new Checkbox("Kanji(Unicode) --> \u6f22\u5b57"));

	List list;
	list = new List();
	list.addItem("Kanji(Unicode) --> \u6f22\u5b57");
	list.addItem("Kanji(Unicode) --> \u6f22\u5b57");
	list.addItem("Kanji(Unicode) --> \u6f22\u5b57");
	add(list);

	Choice chooser = new Choice();
	chooser.add("Kanji(Unicode) --> \u6f22\u5b57");
	chooser.add("Kanji(Unicode) --> \u6f22\u5b57");
	chooser.add("Kanji(Unicode) --> \u6f22\u5b57");
	add(chooser);

	Canvas canvas = new ShowUnicodeCanvas("Kanji(Unicode) --> 
\u6f22\u5b57");
	canvas.setForeground(Color.red);
	canvas.setBackground(Color.white);
	add(canvas);

	resize(500, 500);
	show();
    }

    // \u30a2\u30af\u30b7\u30e7\u30f3\u30a4\u30d9\u30f3\u30c8
    public boolean action(Event e, Object o) {

	// \u30e1\u30cb\u30e5\u30fc\u51e6\u7406
        if (e.target instanceof MenuItem) {
            String s = (String)o;
            if (s.equals("Close")) {
                dispose();
		if (applet != null) {
		    applet.showStatus("Kanji(Unicode) --> \u6f22\u5b57");
		}
            }
            return true;
	}
        return false;
    }

    // \u30cf\u30f3\u30c9\u30eb\u30a4\u30d9\u30f3\u30c8
    public boolean handleEvent(Event e) {
	if (e.id == Event.WINDOW_DESTROY) {
	    // delete, 
close\u30dc\u30bf\u30f3\u304c\u62bc\u3055\u308c\u305f\u3089\u30a6\u30a3\u30f3\u3
0c9\u30a6\u3092\u9589\u3058\u308b
	    dispose();
	    return true;
	}

	// return false; \u3067\u306f\u306a\u304f\u3001
	// 
\u3053\u3046\u3057\u306a\u3044\u3068\u30a2\u30af\u30b7\u30e7\u30f3\u30a4\u30d9\u
30f3\u30c8(action(e,o))\u304c\u547c\u3070\u308c\u306a\u3044
	return super.handleEvent(e);
    }
}

class ShowUnicodeCanvas extends Canvas {
    String label;
    ShowUnicodeCanvas(String label) {
	this.label = label;
    }
    public void paint(Graphics g) {
	Point p = labelPoint(g);
	g.drawString(label, p.x, p.y);
    }
    Point labelPoint(Graphics g) {
	int w = size().width;
	int h = size().height;
	FontMetrics fm = g.getFontMetrics();
	int ascent = fm.getAscent();
	int labelw = fm.stringWidth(label);
	int labelh = ascent + fm.getDescent();
	int x = (w - labelw) / 2;
	int y = (h - labelh) / 2 + ascent;
	return new Point(x, y);
    }
    public Dimension minimumSize() {
	Font font = getFont();
	FontMetrics fm = getFontMetrics(font);
	int labelw = fm.stringWidth(label);
	int labelh = fm.getAscent() + fm.getDescent();
	return new Dimension(labelw, labelh);
    }
    public Dimension preferredSize() {
	Dimension d = minimumSize();
	d.width += 14;
	d.height += 10;
	return d;
    }
}
(Review ID: 23208)
======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: 1.2beta3 FIXED IN: 1.2beta3 INTEGRATED IN: 1.2beta3
14-06-2004

SUGGESTED FIX Please change the following codes in awt packageawt, javaString2multibyte() and multibyte2javaString() should be used for "A" version of win32 API awt_FileDialog.cpp:105: env->GetStringUTFRegion(file, 0, length, fileBuffer); awt_FileDialog.cpp:145: env->NewStringUTF(ofn.lpstrFile)); awt_TextComponent.cpp:275: js = env->NewStringUTF(buffer); /* convert to unicode. */ awt_TextComponent.cpp:315: env->GetStringUTFRegion(text, 0, length, buffer); awt_Window.cpp:586: env->GetStringUTFRegion(title, 0, length, buffer); For example for awt_TextComponent.cpp, the fix should be *** /tmp/geta6303 Thu Mar 5 11:11:02 1998 --- awt_TextComponent.cpp Thu Mar 5 11:19:49 1998 *************** *** 272,278 **** char* buffer = new char[len + 1]; /* Including null terminater */ c->GetText(buffer, len + 1); AwtTextComponent::RemoveCR(buffer); ! js = env->NewStringUTF(buffer); /* convert to unicode. */ delete[] buffer; } } --- 272,279 ---- char* buffer = new char[len + 1]; /* Including null terminater */ c->GetText(buffer, len + 1); AwtTextComponent::RemoveCR(buffer); ! //js = env->NewStringUTF(buffer); /* convert to unicode. */ ! js = AwtFont::multibyte2javaString(env, buffer); delete[] buffer; } } *************** *** 312,318 **** int length = env->GetStringLength(text); char* buffer = new char[length * 2 + 1]; ! env->GetStringUTFRegion(text, 0, length, buffer); buffer = AwtTextComponent::AddCR(buffer, length); c->SetText(buffer); --- 313,320 ---- int length = env->GetStringLength(text); char* buffer = new char[length * 2 + 1]; ! //env->GetStringUTFRegion(text, 0, length, buffer); ! AwtFont::javaString2multibytes(env, text, buffer, length); buffer = AwtTextComponent::AddCR(buffer, length); c->SetText(buffer);
11-06-2004

EVALUATION awt_TextComponent.cpp assumed the UTF encoding (as file code). masayoshi.okutsu@Eng 1998-03-06
06-03-1998