Link to home
Start Free TrialLog in
Avatar of loop_until
loop_until

asked on

Unicode display problem in JList

Hi everyone,

I'm trying to display chess figurines in a Swing JList. I want to use the unicode characters (as described here: http://en.wikipedia.org/wiki/Figurine_notation) to compose a String. As for now, in my JList I always have a square at the place my chess figurines should be. I know it is normally because the font does not support the caracters, I have tried Tahoma, Lucida Sans Unicode, and so on and still nothing. I've looked into Character Map at the specified location and I can't seem to find them, but they print alright in my browser using HTML entities. I've:
  myJList.setFont(new Font('Tahoma', Font.PLAIN, 12))
with all the fonts I could think of and still nothing. I'm missing something here. I create the string as follow:
  String s = "\u265F" + "f2-f3";
for example.

I'd like to be able to use a string to represent the movements and I'd like to be able to distribute easily my program to Windows, Mac or Linux so I'd need a font that can be use everywhere (TTF for example) without installation in the OS if possible.

> I know I could also use icons of the figurines but that's not what I'm trying to do here.

So, where am I missing something? As someone ever printed those unicode chars in their Java program somewhere?

Thanks for your help!
Avatar of udo_borkowski
udo_borkowski

Have you tried to use the "well defined fonts":

- SansSerif
- Serif
- Monospaced

?

Avatar of loop_until

ASKER

Just tried:

  listMoves.setFont(new Font("SansSerif", Font.PLAIN, 12));

Still a big white square.

Any more ideas?
Probably you should use a "full Unicode font" like "Arial Unicode MS".

Please check if you have this installed on your machine.

(see also http://en.wikipedia.org/wiki/Arial_Unicode_MS)

'Arial Unicode MS' is a font only distributed with Microsoft Office, I could not freely distribute it with my program. And I don't understand why it currently prints well in my browser if I don't have the correct font installed already?
Avatar of CEHJ
>>Probably you should use a "full Unicode font" like "Arial Unicode MS".

That font certainly doesn't work for me - nor does Tahoma

>>And I don't understand why it currently prints well in my browser

Do you mean the table at the top of that Wiki page (the bottom is an image)?
Maybe it is using "Lucida Sans Unicode", one of the other common Unicode fonts. It should be installed with newer windows versions. Have a try.

>>Lucida Sans Unicode

No. No dice. My *guess* is that it'd have to be a pretty major Unicode font as those symbols would be pretty low priority for support.
At least with the "Arial Unicode MS" font (that is installed on my machine) the black chess pawn is displayed correctly, using the following code:
---------------
            DefaultListModel model = new DefaultListModel();
            model.addElement("\u265F" + "f2-f3");

            JList list = new JList(model);
            list.setFont(new Font("Arial Unicode MS", Font.PLAIN,24));
---------------
      
Interesting - not for me though. What about the others?
>> Do you mean the table at the top of that Wiki page (the bottom is an image)?

I mean the table at the top. I also recreated a simple html file on my computer, without any font specification (not in CSS nor in HTML) so it uses the default browser font and it displays correctly.

As of Arial Unicode MS, I dont have the font and that won't really solve my problem as it is Microsoft and they rarely gives things away, so there might be licence problem.

They stated Tahoma in the Wikipedia link I gave, does it work for anyone of you guys?
Tahoma did not worked for me.
Glad to see you back CEHJ (well, I'm the one who's back but...)

>> My *guess* is that it'd have to be a pretty major Unicode font as those symbols would be pretty low priority for support.

I think you are right about this but as it seems to be a supported HTML entities (Firefox), I wonder if it's not included somewhere in peoples computer...

Oh! While typing that message, I just tested the Wikipedia page in Explorer and it does not displays correctly. While Firefox does... Anyone knows what unicode support Firefox has?
>> Anyone knows what unicode support Firefox has?

A good one, as it seems.

BTW: I am also using Firefox and had the same idea as you. I search the Firefox installation for some truetype fonts but didn't find one.
>>
BTW: I am also using Firefox and had the same idea as you. I search the Firefox installation for some truetype fonts but didn't find one.
>>

Are you saying that Firefox is displaying chess OK for you?

>>does it work for anyone of you guys?

Nope
Yes, Firefox is displaying okay for me (and seems okay for udo_borkowski too). But not IE.

Seems Firefox has it own (and very good) unicode support.


I don't know if using a HTML component to display the moves would work... I know Swing has a simple HTML component but I'll have to try to see if it displays correctly (I doubt).
>>Seems Firefox has it own (and very good) unicode support.

 The question is, then, where is it coming from? If it hasn't installed fonts in the system and it doesn't seem to have installed them in it own install tree, then where are they coming from?
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
CEHJ: I used your code and tested it with a "chess figure"

I removed the exit to see all fonts and here is what I got:

java.awt.Font[family=Arial Unicode MS,name=Arial Unicode MS,style=plain,size=1]
java.awt.Font[family=Bitstream Cyberbit,name=Bitstream Cyberbit,style=plain,size=1]
java.awt.Font[family=MS Mincho,name=MS Mincho,style=plain,size=1]

Both MS fonts displayed the figure. The Cyberbit figure as just "a white eagle on a white flag" (i.e just white).



Guys, it was fun working with you, but now I have to leave until tomorrow. It is already nearly 2:00 here in Germany.

loop_until: nice riddle ;-)
That's weird - i could have sworn i had Arial Unicode MS, but apparently not. I have none of the other two either

>>I removed the exit

Yes, another 'non single exit point' - i might get wrapped across the knuckles ;-)
Thanks CEHJ, with your little snippet I was able to found I could use 'MS Gothic' on my computer. Well, at the moment this is not very portable: I'd like it to run on Linux and Mac also but I'll see later about that. Close enought. I guess I could make this piece of code search quickly at the start for a valid font.

Thanks for the help.
udo_borkowski, thanks also for your help, but for the HTML entities, this is not part of the question, I had specifically said:

  > I know I could also use icons of the figurines but that's not what I'm trying to do here.

Anyway, I didn't know we could use some HTML in a JList. I'll raise the points a little and share with you for giving a couple of ideas, I like it when a lot of ideas come along! ;-)
>>I guess I could make this piece of code search quickly at the start for a valid font.

Yes, but to be certain you've really got to be prepared to install your own font or use images as Udo suggested
I guess if it displays sometimes a "White Eagle" that I will not be able to make a snippet to detect a valid font... Well, at least I was able to display on my computer. Well, personnal work should be more fun than stress, so I'll think of something else for distributing my little game.

Actually using html entities is a bit irrelevant as the system can only render them as it renders anything else. This is more related to an en/decoding scenario.

Interestingly though, characters that refuse to render normally in a browser can sometimes be forced to appear by making them entities - don't ask me why
I'm going to distribute the points so you're not tie here for the rest of your life but if you ever have a great idea for having the unicode chess figurines available OS-wide easily, I'll be glad to hear from it.

Have a nice evening (night) everyone!
>>I guess if it displays sometimes a "White Eagle"

That's an odd one - mistake in font or decoding (more likely the former). That doesn't affect the detection logic you've got in mind (the Unicode character set is certainly fixed)
8-)
First:
I found the following page that lists "free" Unicode fonts: http://www.slovo.info/unifonts.htm


Second:
I tried the Code2000 font (http://home.att.net/~jameskass/CODE2000.ZIP).

It is a shareware font you can try for free. "If you like it and use it after a reasonable evaluation period, you are obliged to register the font by sending me $5 (Five U.S. Dollars, or equivalent in any currency.)" (http://www.slovo.info/code2000.htm)

AND IT WORKS! That font also contains chess figures (not just "white eagles")


Third:
 8-)