简体   繁体   中英

Unicode in Java Graphics not displaying

What do I have to do in order to get text instead of the boxes?

在此处输入图片说明

I have a web service to create icons for a web page.

The text starts as: ニホンフジサワ ステーク / 日本藤…

Its then encoded in javascript to: %EF%BE%86%EF%BE%8E%EF%BE%9D%EF%BE%8C%EF%BD%BC%EF%BE%9E%EF%BD%BB%EF%BE%9C%20%EF%BD%BD%EF%BE%83%EF%BD%B0%EF%BD%B8%20/%20%E6%97%A5%E6%9C%AC%E8%97%A4%E2%80%A6

I pick it up in Java on the server as the correct string. So I know its not a serializing error.

A subquestion would be why does it display as the boxes in my debugger(using IntelliJ), but when I click it to set the text, it displays the correct text?

在此处输入图片说明在此处输入图片说明

I know the string is there, now I'm at a complete loss how to get Graphics2D to display that. I have tried using drawString(), drawBytes(), encoding the string, sending in a string of unicode values, and nothing works.

I have gotten it to work if the unicode values are Latin based, such as French and Spanish vowels. This leads me to wonder if its some kind of language/locale issue.

Any help would be greatly appreciated.

Generally this issue arises when the font you are using does not have the glyphs for the characters you are trying to display. Many fonts do not support the full range of Unicode characters, and so will just display a box for the character instead. If you change the font you are using to one with full Unicode support, the characters should display correctly.

I did find a helpful resource which led me to discover the problem before David posted. Since it was the same fix, I gave him the best answer. But I did want to post the link that helped me to give credit where its due and help anyone else that might have the same problem.

http://users.erols.com/eepeter/chinesecomputing/programming/java.html

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