Java not displaying a special UTF symbol?

2019-08-11 01:48发布

I have successfully been calling Unicode characters in Java. However, I cannot call this particular symbol of a pedestrian... http://www.fileformat.info/info/unicode/char/1f6b6/index.htm

I am following the directions on the website but it displays an empty block:

JOptionPane.showMessageDialog(null,"\uD83D\uDEB6");

What am I doing wrong?

2条回答
家丑人穷心不美
2楼-- · 2019-08-11 02:13

It's not necessarily that you're doing something wrong (though you failed to give a code example in context).

Bear in mind, if you didn't already know, that most computers have only a portion of the unicode set installed. There are a number of funny characters like that that won't work on every computer.

Some are safe - like the accented á, etc. - but not all of them.

Generally, if you found one that wasn't installed on your computer, I would avoid trying to get it onto your computer - if you ever plan for that Java program to run anywhere else (which is the idea of Java, right?) - since your program would fail on any other computer without it.

Sorry to disappoint - I've felt the same disappointment when I found cool things that didn't work in unicode.

http://smallbusiness.chron.com/unicode-symbols-not-display-java-39315.html

http://knowyourmeme.com/memes/this-is-bob

查看更多
欢心
3楼-- · 2019-08-11 02:15

This is a font issue. The font(s) being used do(es) not contain a glyph for the character, hence the rendering software displays a generic symbol like a rectangle instead.

If you follow the link Fonts that support U+1F6B6 on the page you mention in the question, you will get the information that only Symbola contains the character PEDESTRIAN (U+1F6B6). (The LastResort font mentioned there is a pseudo-font, useful in software development but not in rendering characters.) This should not be a surprise, as it was introduced in Unicode 6, in 2010. It generally takes about ten years or more for a character to get reasonably well supported in fonts.

Sufficiently new versions of Segoe UI Symbol also contain U+1F6B6, but Segoe UI Symbol is proprietary, shipped with Windows 7 and Windows 8, and you may need an update to it to get a version that supports U+1F6B6. Symbola, on the other hand, is a free font.

查看更多
登录 后发表回答