Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to display Chinese in TextArea

 
ego hu
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 300
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).]
 
ego hu
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 428
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 428
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
TextArea ta=new TextArea();
BUT DOESN'T DISPLAY JAPANESE LANG.!!!
Angela[/B]

If you can, use Swing. It will make your adventure much simpler.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic