简体   繁体   English

JLabel:带重音字母的问题

[英]JLabel: issue with accented letters

I read some string data from a JSON web service. 我从JSON Web服务读取了一些字符串数据。

When I put the result string (with accented letters) into a JLabel I see the following result: 当我将结果字符串(带有重音字母)放入JLabel我看到以下结果: 在此处输入图片说明

but the string should contain: Lèttèrè àccèntàtè - àà èè ìì ò 但字符串应包含: Lèttèrèàccèntàtè-ààèèììò

I use this code for declare the JLabel : 我使用此代码声明JLabel

JLabel descriptionLabel = new JLabel(myString);

If I try to put this string into a .txt file a read the correct string ( Lèttèrè àccèntàtè - àà èè ìì ò ). 如果尝试将此字符串放入.txt文件,请读取正确的字符串( Lèttèrèàccèntàtè-ààèèììò )。

Is it an issue related to the charset that I use? 这与我使用的字符集有关吗?

This works for me, check if it works for you too and we can continue from there. 这对我有用,请检查它是否也对您有用,我们可以从那里继续。

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

Edit : Now try to replace all accented characters in your string with the following unicode strings and set them in the label. 编辑 :现在尝试用以下unicode字符串替换字符串中的所有重音字符,并将它们设置在标签中。

á   \u00e0  Á   \u00c0
à   \u00e1  À   \u00c1
â   \u00e2  Â   \u00c2
é   \u00e9  É   \u00c9
è   \u00e8  È   \u00c8
ê   \u00ea  Ê   \u00ca
î   \u00ee  Î   \u00ce
ç   \u00e7  Ç   \u00c7

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM