Hi! does anyone know how to output chinese character into a window in java.. I have google so many times and found nothing..any help would be nice ...thank you
Output chinese character in GUI
Page 1 of 16 Replies - 1209 Views - Last Post: 22 September 2009 - 11:31 PM
Replies To: Output chinese character in GUI
#2
Re: Output chinese character in GUI
Posted 22 September 2009 - 04:31 AM
Yes, you can do it.
You have to set the encoding from default(Cp1252) to UTF-8.
It worked for me on Eclipse.
You have to set the encoding from default(Cp1252) to UTF-8.
It worked for me on Eclipse.
import java.awt.BorderLayout;
import java.awt.Color;
import javax.swing.*;
public class UseCustomFrame extends JFrame{
private JLabel jlblChin = new JLabel("可以打華語字耶!!");
public UseCustomFrame(){
JPanel p1 = new JPanel();
p1.add(jlblChin);
add(p1, BorderLayout.CENTER);
}
public static void main(String[] args) {
UseCustomFrame frame = new UseCustomFrame();
frame.setTitle("Hehe");
frame.setSize(200, 100);
frame.setLocation(200, 100);
frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
frame.setVisible(true);
frame.getContentPane().setBackground(Color.yellow);
}
}
This post has been edited by AntonWebsters: 22 September 2009 - 04:34 AM
#3
Re: Output chinese character in GUI
Posted 22 September 2009 - 05:53 AM
Cut and paste unicode support can be a pitfall. I'd used Java's unicode notation. This assumes the OS has some level of font support for the language in question.
import java.awt.*;
import javax.swing.*;
public class ChineseTest extends JFrame{
public ChineseTest() {
addText(
"\u4F60" // unicode ni
+ "\u597D" // unicode hao
);
setTitle("Does your Java speak Chinese?");
setDefaultCloseOperation(EXIT_ON_CLOSE);
pack();
}
private void addText(String s) {
JLabel lab = new JLabel(s);
Font f = lab.getFont();
lab.setFont(new Font(f.getFontName(), f.getStyle(), f.getSize()*5));
add(lab);
}
public static void main(String[] args) {
new ChineseTest().setVisible(true);
}
}
#4
Re: Output chinese character in GUI
Posted 22 September 2009 - 07:06 AM
Does Locale come into play in this? *is curious....*
#5
Re: Output chinese character in GUI
Posted 22 September 2009 - 09:39 PM
Hey! thx all...anton. I tried your method tho, if other computer does not support the chinese font ??? will appear...and baavgi I tried yours hence, do you know where I might find a list of the chinese uni-code??
#6
Re: Output chinese character in GUI
Posted 22 September 2009 - 11:08 PM
Here's a Chinese character to Unicode converter...
http://weber.ucsd.ed...icodemaker.html
After converting, make sure you add "\u" in front of the unicodes when you want to use them.
For example, 597D should be \u597D.
http://weber.ucsd.ed...icodemaker.html
After converting, make sure you add "\u" in front of the unicodes when you want to use them.
For example, 597D should be \u597D.
#7
Re: Output chinese character in GUI
Posted 22 September 2009 - 11:31 PM
ohh cool..i found that program on google before but wasn't sure how to use it..now i got it i have to type the chinese character in the it translate for me and uses the hex value...
Thx a lot..
Thx a lot..
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote









|