1

I am trying to draw random Nordic runes in a little Java game, but all I'm getting back is a square character.

public class MyComponent extends JComponent {
    public void paintComponent(Graphics g) {
        String s = "\u16A8";
        g.drawString(s,50,50);
    }
}

What the character should be displaying: https://en.wikipedia.org/wiki/Ansuz_(rune)

What it's actually displaying: ⃣

So what's going on here? Why isn't it displaying the unicode character?

Perry Monschau
  • 883
  • 8
  • 22

1 Answers1

2

The font that Java defaults to varies from platform to platform. To ensure that a unicode character is always displayed properly, you should set to a font that you are sure contains the glyph.

You can set the font as such, before calling the drawString() method

Font font = new Font(Font.MONOSPACED, Font.PLAIN, 11);
g.setFont(font);
AngelTrs
  • 236
  • 1
  • 8
  • There anywhere I can go to find out which font has it? Font.MONOSPACED does not. – Perry Monschau Jun 18 '15 at 01:14
  • 1
    @PerryMonschau sorry about that, I used monospaced for example purposes. Check out this link: http://www.fileformat.info/info/unicode/char/16a8/fontsupport.htm You can also use the Local Font List tool there to see how and if your machine's fonts will display it. – AngelTrs Jun 18 '15 at 01:38
  • Yes, thank you. Though I have one further question. How would I go about ensuring another computer has the font I'm requesting? Is there a way to include it with the source code and reference that? – Perry Monschau Jun 18 '15 at 13:49
  • 1
    Very welcome, glad I could help. Do you mean to include the font with your package/jar file? check out this question and see if it helps: http://stackoverflow.com/questions/5652344/how-can-i-use-a-custom-font-in-java – AngelTrs Jun 18 '15 at 14:02