Redian新闻
>
Question about displaying Chinese
avatar
Question about displaying Chinese# Java - 爪哇娇娃
e*n
1
I wrote a small program to display Chinese, but I can not display Chinese
correct.
Here is my code:
try
{
String s1 = "讨论";
JLabel jlTemp = new JLabel("Display: " + s1);
}
catch(Exception e)
{
}
In this case, the JLabel display garbage on the screen.
try
{
String s1 = "讨论";
String s2 = new String(s1.getBytes(), "GBK");
JLabel jlTemp = new JLabel("Display: " + s2);
}
catch(Exception e)
}
In this case, the JLabel display "????" on the screen.
Can someone tell me where my proble
avatar
f*h
2
look at the font property file under $JAVA_HOME/jre/lib
you need to specify the chinese font there.
google bah.

【在 e**n 的大作中提到】
: I wrote a small program to display Chinese, but I can not display Chinese
: correct.
: Here is my code:
: try
: {
: String s1 = "讨论";
: JLabel jlTemp = new JLabel("Display: " + s1);
: }
: catch(Exception e)
: {

avatar
e*n
3
The font property is not the problem.
I found an example using Chinese in "\u6839\u636e" format. If I use s1 =
"\u6839\u636e" in my program, I can display it in Chinese correctly. But the
problem is, how am I going to implement? How can I convert all Chinese into
\uxxxx format?

【在 f********h 的大作中提到】
: look at the font property file under $JAVA_HOME/jre/lib
: you need to specify the chinese font there.
: google bah.

avatar
f*h
4
did you set up correct encoding in your code?

【在 e**n 的大作中提到】
: The font property is not the problem.
: I found an example using Chinese in "\u6839\u636e" format. If I use s1 =
: "\u6839\u636e" in my program, I can display it in Chinese correctly. But the
: problem is, how am I going to implement? How can I convert all Chinese into
: \uxxxx format?

avatar
w*c
5
native2ascii

Chinese

【在 e**n 的大作中提到】
: The font property is not the problem.
: I found an example using Chinese in "\u6839\u636e" format. If I use s1 =
: "\u6839\u636e" in my program, I can display it in Chinese correctly. But the
: problem is, how am I going to implement? How can I convert all Chinese into
: \uxxxx format?

avatar
e*g
6
then it's source file encoding problem. your editor uses one encoding to
to save file, probably GB, but javac doesn't know that. check javac
command line options to tell it the encoding.

【在 e**n 的大作中提到】
: The font property is not the problem.
: I found an example using Chinese in "\u6839\u636e" format. If I use s1 =
: "\u6839\u636e" in my program, I can display it in Chinese correctly. But the
: problem is, how am I going to implement? How can I convert all Chinese into
: \uxxxx format?

avatar
t*s
7
Also, unless you specify it, default encoding is based on your platform.

【在 e***g 的大作中提到】
: then it's source file encoding problem. your editor uses one encoding to
: to save file, probably GB, but javac doesn't know that. check javac
: command line options to tell it the encoding.

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。