如何在Java上unicode缅甸文本? [英] How to unicode Myanmar texts on Java?

查看:369
本文介绍了如何在Java上unicode缅甸文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只是Java的初学者。

我正在尝试在Java GUI(Swing / Awt)上正确地unicode(显示)缅甸文本。

我有四个TrueType字体,支持缅甸unicode文本。有缅甸3,Padauk,Tharlon,缅甸文本(内置Window 8)。

您可能需要在代码之前使用字体。谷歌的字体,请。

每个字体在Java GUI上显示的方式不同且不正确。



这是GUI标签显示的代码缅甸文:

+++++++++++++++++++++++++++++++++++++++++++++ b

  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);
字符串 s = \ u1015 \\ \\ u102F \\\ြ\\\ပ\\\ု;
JLabel label = new JLabel(s);
label.setFont( new java.awt.Font( Myanmar3 0 20 )); // 字体插入此处,缅甸文本,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 ();
}
});
}
}





++++++++++++++++++++++++++++++++++++++++ ++++++

输出各不相同。看图片:

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



缅甸文IMG: http://i.stack.imgur.com/qbmH3.png



什么是正确的表格? (在记事本上)



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



好​​了,接下来是GUI Textfield输入缅甸文本的代码:

++ ++++++++++++++++++++++++++++++++++++++ / span> 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 ();
}
});
}
}





++++++++++++++++++++++++++++++++++++++++ ++++++

当我在键盘上输入键(unicode文本)时,输出会有所不同。

缅甸文本输出IMG:http://i.stack.imgur.com/0icXd.png



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



缅甸3输出IMG: http://i.stack.imgur.com/aXLaa.png



Tharlon输出IMG: http:/ /i.stack.imgur.com/nqxKA.png





打开文本时,这些字体在Linux上运行良好文本编辑器应用程序的文件。

我的问题是如何在Java GUI上解码缅甸文本。我还需要额外的代码才能显示好吗?或Java仍然有错误?字体在Web应用程序(HTML,CSS)上显示良好,但我不确定是否在Java Web Application上显示。

解决方案

Yepp - 可以...好吧,让我们说复杂。我必须在我的应用程序中处理多种语言,这总是很有趣:



1.机器必须能够显示语言

当您能够将键盘布局更改为特定语言时,机器也应该能够显示语言。

这很重要,因为机器无法正确显示字体当使用假字体时。



2.你需要指定你正在使用的字符串是UTF-8:字符编码和字符串 - Java教程 [ ^ ]

PLease也阅读了该教程的其他页面,它编写得非常好加载信息。



3.属性文件可以在文件属性中设置为UTF-8。

还可以查看相当不错的 ResourceBundleEditor [ ^ ],可帮助您创建正确的i18n文件。一个体面的应用程序框架也可以帮助你。



4.注意:不同语言中的同一个单词可以有不同的大小。

例如像地址这样的英文单词可以有一个长期的外国谚语人居住的地方。

一般标签,表格和GUI的巨大差异!这真的毁了这一天。所以请尝试使用浮动布局。



5.混合字符串需要处理得好。

当你将英语与外语混合时(特别是RTL语言)你可以得到一个混合的结果。你需要意识到这一点。

文本中的制表符步骤通常也不起作用。


'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:
++++++++++++++++++++++++

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:
++++++++++++++++++++++++

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.

解决方案

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.


这篇关于如何在Java上unicode缅甸文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆