2

Is there any reason why unicode characters are not appearing when my Java program is run on someone else's laptop (Windows)?

I have written a Chess program in Java (Swing) on my Mac. Each piece is represented by a unicode character of that Chess piece. The board is shown as a grid of buttons each of which has its text set to a Chess unicode character.

On my Mac it works fine but my friend (using windows) says that although the grid of buttons appear he cannot see any Chess characters. Luckily I set each buttons' tooltip to be the name of the piece it is representing and this allowed him to test the game however as I'm sure you understand having to hover your mouse above every square just to know what is there is time consuming. Despite this it did show that my program was working fine just was not displaying any unicode.

What can I do to my program or my friends settings on his laptop to resolve this?

Saad Attieh
  • 1,396
  • 3
  • 21
  • 42
  • That's very hard to answer without seeing the relevant parts of your code. – jlordo Jan 06 '13 at 09:48
  • 3
    Maybe on Windows a font is used that can not display those characters? You should make the used font configurable and try again. –  Jan 06 '13 at 09:48
  • Try this [variation](http://stackoverflow.com/a/2563350/230513) on this [example](http://stackoverflow.com/a/2562685/230513). – trashgod Jan 06 '13 at 10:06
  • @a_horse_with_no_name actually I have set the font of the buttons like this. private Font font = new Font(null, Font.PLAIN, 36); button.setFont(font); I used null because apparently in the API this uses a default font. I set the size to be 36 because the characters appeared tiny otherwise. Should I change the null statement? jlordo I will try to put a small example of the GUI code. Is there any way I can attach a Jar file which people could test on this site? By testing I mean just running and see if their system will display the unicode? – Saad Attieh Jan 06 '13 at 10:19
  • it might be better to use the default font and simply increase it size: `getFont().deriveFont((float)36)`. `getFont()` should be called on the component that displays the pieces. –  Jan 06 '13 at 11:32

1 Answers1

2

This variation on this example works correctly on Windows 7 using the default Font for the family Font.SANS_SERIF, which contains the required glyphs.

static Font font = new Font(Font.SANS_SERIF, Font.PLAIN, 72);

enter image description here

In contrast, you've set the name to null; as a result, "the logical font name of the new Font as returned by getName() is set to the name Default."

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045