问题描述:

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
相关阅读:
Top