sasquatch
sasquatch

Reputation: 285

Unicode in Java Graphics not displaying

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

enter image description here

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?

enter image description here enter image description here

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.

Upvotes: 0

Views: 453

Answers (2)

sasquatch
sasquatch

Reputation: 285

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

Upvotes: 0

David Gilbert
David Gilbert

Reputation: 4477

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.

Upvotes: 1

Related Questions