简体   繁体   中英

JLabel: issue with accented letters

I read some string data from a JSON web service.

When I put the result string (with accented letters) into a JLabel I see the following result: 在此处输入图片说明

but the string should contain: Lèttèrè àccèntàtè - àà èè ìì ò

I use this code for declare the 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è - àà èè ìì ò ).

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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