有些脚本无法在JPanel中正确显示,即使以UTF-8编码也是如此?

时间:2015-09-26 16:13:58

标签: java utf-8 character-encoding jpanel

所以我只是为自己制作这个小Java应用程序,用于处理不同的语言(虽然我还不知道哪种语言),这意味着它应该能够处理不同的语言脚本。问题是似乎某些脚本(例如缅甸语)没有正确显示。下图显示了我的意思: http://i.stack.imgur.com/1WQ52.png

正如您所看到的,大多数脚本似乎都运行良好,甚至更加模糊,例如格鲁吉亚语和更复杂的例如中文。但其他脚本无法正确显示。有办法解决这个问题吗?

有关信息,这是我浏览以显示上述图片的确切过程:

1)从.txt文件中读取(.txt文件以UTF-8编码,所有不同的脚本都显示正常),如下所示:

try {
    fis = new FileInputStream("text file as path");
} catch (FileNotFoundException e) {
    e.printStackTrace();
}
try {
    br = new BufferedReader(new InputStreamReader(fis,"UTF8"));
} catch (UnsupportedEncodingException e) {
    e.printStackTrace();
}
    //more stuff...
try {
    while((lineStr = br.readLine()) != null){
        //Store lineStr in a String[] array...
    }
    br.close()
} catch (IOException e) {
    e.printStackTrace();
}

2)一旦这些行在String []变量中(称为" linesArray"),我将在JPanel中显示它们:

JLabel[] labels = new JLabel[linesArray.length];
String labeltext = new String();
for(int i=0;i<linesArray.length;i++){                   
    labeltext = String.format("<html><div WIDTH=%d>%s</div><html>", 139, linesArray[i]);
    labels[i] = new JLabel(labeltext);
    labels[i].setForeground(Color.RED);
    //set bounds and add to the JPanel
}

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

您使用的字体可能不包含您想要显示的字符。