简体   繁体   中英

Displaying special unicode characters in Java/Swing

I wanted to draw special characters like this one ( http://www.fileformat.info/info/unicode/char/2605/index.htm ) in JLabel. It's working great on Mac OS X.

To avoid encoding problem, I've defined this like that :

public static final char STAR = '\u2605';

But on Windows 7, I've got a square representing an unknown character. I've googled and it looks like we need to hand-edit the font configuration files that the JRE uses.

I would like my application to be portable and not requiring this kind of intervention from the user.

Any idea is appreciated. Many thanks !

The problem is most likely that the specific character is not part of the font on the windows platform. This is the case for many higher unicode chars. You need to find one that exists on all platforms.

It's even the case that a typeface called the same on different platforms may have entirely different support of chars. You could try switching the typeface and see if you can find one that has the star consistently across platforms.

Your encoding of the unicode char is completely portable.

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