我从 JSON Web 服务读取了一些字符串数据。
当我将结果字符串(带有重音字母)放入 JLabel
中时,我看到以下结果:
但字符串应包含:Lèttèrè àccèntàtè - àà èè ìì ò
我使用此代码来声明 JLabel
:
JLabel descriptionLabel = new JLabel(myString);
如果我尝试将此字符串放入 .txt 文件中,则会读取正确的字符串 (Lèttèrè àccèntàtè - àà èè ìì ò)。
这是否与我使用的字符集有关?
最佳答案
这对我有用,请检查它是否也适合您,我们可以从那里继续。
public class AccentedLabel extends JFrame {
public AccentedLabel() {
JLabel label = new JLabel("áéêè");
add(label);
setLocationRelativeTo(null);
setDefaultCloseOperation(EXIT_ON_CLOSE);
pack();
setVisible(true);
}
public static void main(String[] args) {
new AccentedLabel();
}
}
编辑:现在尝试用以下 unicode 字符串替换字符串中的所有重音字符,并将它们设置在标签中。
á \u00e0 Á \u00c0
à \u00e1 À \u00c1
â \u00e2 Â \u00c2
é \u00e9 É \u00c9
è \u00e8 È \u00c8
ê \u00ea Ê \u00ca
î \u00ee Î \u00ce
ç \u00e7 Ç \u00c7
关于java - JLabel:重音字母问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23655889/