Click here to Skip to main content
15,878,959 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
'm just beginner of Java.
I'm trying to unicode (display) correctly Myanmar texts on Java GUI ( Swing/Awt ).
I have four TrueType fonts which support Myanmar unicode texts. There are Myanmar3, Padauk, Tharlon, Myanmar Text ( Window 8 built-in ).
You may need the fonts before the code. Google the fonts, please.
Each of the fonts display on Java GUI differently and incorrectly.

Here is the code for GUI Label displaying myanmar texts:
++++++++++++++++++++++++

Java
package javaapplication1;
import javax.swing.JFrame;
import javax.swing.JTextField;
public class CusFrom {
private static void createAndShowGUI() {
JFrame frame = new JFrame("Hello World Swing");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
String s = "\u1015\u102F \u103C\u1015\u102F";
JLabel label = new JLabel(s);
label.setFont(new java.awt.Font("Myanmar3", 0, 20));// font insert here, Myanmar Text, Padauk, Myanmar3, Tharlon
frame.getContentPane().add(label);
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
} 


++++++++++++++++++++++++
Outputs vary. See the pictures:
Myanmar3 IMG: http://i.stack.imgur.com/s0WBN.png

Padauk IMG: "http://i.stack.imgur.com/vkjdt.png

Tharlon IMG: "http://i.stack.imgur.com/FpPg0.png

Myanmar Text IMG: http://i.stack.imgur.com/qbmH3.png

What is the correct form? (on notepad)

http://i.stack.imgur.com/SrNqY.png

Well, next is the code for GUI Textfield inputting Myanmar texts:
++++++++++++++++++++++++
Java
package javaapplication1;
import javax.swing.JFrame;
import javax.swing.JTextField;
public class XusForm {
private static void createAndShowGUI() {
JFrame frame = new JFrame("Frame Title");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JTextField textfield = new JTextField();
textfield.setFont(new java.awt.Font("Myanmar3", 0, 20));
frame.getContentPane().add(textfield);
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}


++++++++++++++++++++++++
Outputs vary when I input keys( unicode text ) on keyboards.
Myanmar Text Output IMG: http://i.stack.imgur.com/0icXd.png

Padauk Output IMG: http://i.stack.imgur.com/I0qMX.png

Myanmar3 Output IMG: http://i.stack.imgur.com/aXLaa.png

Tharlon Output IMG: "http://i.stack.imgur.com/nqxKA.png"


Those fonts work well on Linux when opening text files with Text Editor application.
My Question is how to unicode Myanmar texts on Java GUI. Do I need additional codes left to display well? Or Does Java still have errors? The fonts display well on Web Application (HTML, CSS) but I'm not sure about displaying on Java Web Application.
Posted
v2

1 solution

Yepp - that can be...well, let's say "complicated". I have to deal with several languages in my applications, that's always fun:

1. the machine has to be able to display the language
When you're able to change keyboard layout to the specific language, then the machine should be capable to display the language too.
This is important, as the machine is not able to display the fonts correctly when using the false font.

2. you need the specify that the String you're working with is UTF-8: Byte Encodings and Strings - The Java Tutorial[^]
PLease also read the other pages of that tutorial, it's pretty well written and loaded with infos.

3. Properties files can be set in the file-properties to be UTF-8.
Also check out the pretty nice ResourceBundleEditor[^] for Eclipse IDE, which helps you to create correct i18n files. A decent application framework would also help you in that.

4. be aware: the same word in different languages can have different sizes.
E.g. A simple word in English like "address" can have a long foreign saying "place where the person is living".
Huge difference in labels, forms and GUI in general! This can really ruin the day. So please try to use floating layouts.

5. mixed Strings need to be handled well.
When you mix English with foreign languages (especially RTL-languages) you can get a mixed up result. You need to be aware of that.
Also tabulator steps in the text are often not working.
 
Share this answer
 
v2
Comments
Spacez Ly Wang 25-Dec-12 10:44am    
Thank for your reply.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900