3

Short of copying the character to the clipboard and pasting it inside my string, is there a way to draw a greek letter (or for that matter, any unicode character)? I know the code for the character I am trying to draw is U+03F4 according to here. I have tried the following:

g.drawString("U+03F4", 100, 100); // works as a string literal as it should
g.drawString("\U+03F4", 100, 100); // error: Illegal escape character
g.drawString("\\U+03F4", 100, 100); // thought I could trick it. Just draws "\U+03F4"

I saw in this question that the 'u' was lowercase but that didn't make any difference.

Why would this not be working?

Community
  • 1
  • 1
BitNinja
  • 1,477
  • 1
  • 19
  • 25

3 Answers3

6

The general format for Java unicode escapes is

UnicodeEscape:
    \ UnicodeMarker HexDigit HexDigit HexDigit HexDigit

UnicodeMarker:
    u
    UnicodeMarker u

Therefore correct sequence for this character in Java is \u03F4.

http://www.fileformat.info/info/unicode/char/03F4/index.htm

Community
  • 1
  • 1
Matt Ball
  • 354,903
  • 100
  • 647
  • 710
4

I think the correct way to represent a unicode character is as follows:

g.drawString("\u03f4", 100, 100);
Cᴏʀʏ
  • 105,112
  • 20
  • 162
  • 194
2
g.drawString("\u03f4", 100, 100);

if you want to get a char, use '\u03f4', but in this case use double quotes since you want it to be a String.

Victor2748
  • 4,149
  • 13
  • 52
  • 89