aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes How to display Chinese in TextArea Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to display Chinese in TextArea" Watch "How to display Chinese in TextArea" New topic
Author

How to display Chinese in TextArea

ego hu
Ranch Hand

Joined: Mar 20, 2001
Posts: 53
I need to display Chinese characters on TextArea,
but did not succeed. I tried both TextArea and JTextArea.
Please help. what shoud I do?
setFont?
setLocale?
how to change encoding?
The OS is Windows NT4.0 English version.
Thanks.
[This message has been edited by ego hu (edited May 03, 2001).]
Fred Abbot
Ranch Hand

Joined: Jun 01, 2000
Posts: 300
hi
you have to set the font to a font that supports chinese characters.
what is the key to get the charcter?
ego hu
Ranch Hand

Joined: Mar 20, 2001
Posts: 53
I tried following code:
JTextArea ta=new JTextArea();
ta.setLineWrap(true);
ta.setFont( new Font("MS Song", Font.PLAIN, 14));
ta.setLocale(new Locale("zh", "CN"));
......
ta.setText("something in Chinese @#$%&&%$#@");
What the TextArea showed is unreadable. But if I copy some
Chinese text from another editor and paste it to the TextArea, it can be displayed correctly.
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
You have to enter the text using unicode.
\u1234
You may wish to pick up "Java Internationalization" if you are going to be working with Chinese characters.
[This message has been edited by Thomas Paul (edited May 03, 2001).]


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
ego hu
Ranch Hand

Joined: Mar 20, 2001
Posts: 53
Thank you for your reply.
In fact the contents is obtained from a file, and
I got it in String type.
Can you tell me, how to get a String in Unicode form?
Thanks.
Angela Jessi
Ranch Hand

Joined: Nov 27, 2000
Posts: 428
Hi,
I have question here:
I am working on Client Side developement project right now. Server is sending me Unicode characters like : {0x83,0x76,0x83,0x8a,0x83,0x93,0x83,0x5e,0x00}(This is Unicode characters for Japanese Language)
Now I have to convert this characters to display Japanese(Kanji) Language in Browser. How can I do it?
If anybody can explain by example. B'cos I read Internalization docs, but I can't understand properly.
Thanks,
Angela
Angela Jessi
Ranch Hand

Joined: Nov 27, 2000
Posts: 428
Hi,
I have this following example :
import java.applet.Applet;
import java.awt.*;
import java.util.*;
public class langDemo extends Applet
{
public void init()
{
TextArea ta=new TextArea();
ta.setFont( new Font("Lucida Sans Unicode", Font.PLAIN,14));
ta.setLocale(new Locale("ja", "JP"));
ta.setText("{0x83,0x76,0x83,0x8a,0x83,0x93,0x83,0x5e,0x00}");
add(ta);
}
}
BUT DOESN'T DISPLAY JAPANESE LANG.!!!
Please help me out,
Thanks,
Angela
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
Originally posted by ego hu:
Thank you for your reply.
In fact the contents is obtained from a file, and
I got it in String type.
Can you tell me, how to get a String in Unicode form?
Thanks.

Strings automatically support unicode. You must use a Reader and not an InputStream to read your file. (InputStreams do not support unicode as they do byte reads.)
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
TextArea ta=new TextArea();
BUT DOESN'T DISPLAY JAPANESE LANG.!!!
Angela[/B]

If you can, use Swing. It will make your adventure much simpler.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to display Chinese in TextArea
 
Similar Threads
insert chinese character jsp/java servlet
formatting the textarea form field in a servlet
how to input chinese?
displaying words in different fonts or colors in a textarea
insert chinese language to mysql db