Can I use Unicode characters in the Java GUI?

For the play button in the Java GUI, I am currently using a button with a label set to 'β–»' (found this character in the Unicode character table). As far as I understand, it’s better not to use such characters directly in the source code, but rather use an explicit unicode representation, for example \u25BB in this example, because some tools (editor, ...) may not be able to process files, -ASCII ( it is right?).

Assuming the compiled class contains the correct character, under what circumstances does the graphical interface not display the intended character in the current PC operating system? Linux, Windows, Mac must support UTF-16, right? Are fonts available or font settings causing problems with this approach?

(Of course, I could add an icon, but why add additional resources if the symbol is already available ... given that this is a portable solution)

+4
source share
3 answers

Are fonts or font settings available for this approach?

Unfortunately, they do it. Of course, you can use unicode in the source code, but the problem is that unicode currently has 246,943 code points, so there is clearly no font that even has a fraction of those defined. You will get squares or some other weird rendering when the glyph is not available. I have had cases where relatively simple characters, such as Β³, were displayed on one Windows computer and displayed as squares in the next, almost identical computer. This is influenced by all kinds of language and local settings and minor version changes, so they are quite fragile.

AFAIK, there are several, if any, characters that will always be available. The Java Font class has some methods, such as canDisplay and canDisplayUpTo , which can be useful for checking this at runtime.

Instead of using the icons, you can associate some nice TrueType font that has the special characters you need, and then use that font throughout your application.

+5
source
 I currently use a button with the label set to ' β–» ' 

and not I always use JButton (line text, icon icon) and Icon does not matter if it exists Font or another Font , UTF-16 or Unicode

+3
source

Most editors support Unicode, so go ahead.

Take a look at this entry: French Eclipse Support

If you use a simple editor, such as a notepad, then when you save the type name and below, select the UTF encoding ( http://www.sevenforums.com/software/72727-how-make-notepad-save-txt-files-unicode .html )

+1
source

All Articles