Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unicode symbols (arrows) in Java

i want to use following symbols for buttons in my app:

arrows http://img402.imageshack.us/img402/3176/arrowso.jpg

here my code:

Button goToFirstButton = new Button("\uE318");
Button prevPageButton = new Button("\uE312");
Button nextPageButton = new Button("\uE313");
Button goToLastButton = new Button("\uE319");

and the result is

result http://img693.imageshack.us/img693/9063/resultbu.jpg

It seems, that \uE318 and \uE313 are wrong. What should i use instead? For goToLastButton and goToFirstButton i prefer to use this images

alt text http://img3.imageshack.us/img3/5724/singlearrow.jpg

but i can't find, which code should i use.

like image 525
cupakob Avatar asked Feb 02 '10 09:02

cupakob


People also ask

How do you type an arrow in Java?

When more than one parameter is passed, they are separated by commas. To support lambdas, Java has introduced a new operator “->”, also known as lambda operator or arrow operator. This arrow operator is required because we need to syntactically separate the parameter from the body.

How do you write Unicode characters in Java?

Unicode character literals To print Unicode characters, enter the escape sequence “u”. Unicode sequences can be used everywhere in Java code. As long as it contains Unicode characters, it can be used as an identifier.


3 Answers

I would suggest to use Icons on Buttons instead of special characters, because the ability to display may be strongly affected by availability of fonts on client workstation.

like image 163
Artyom Avatar answered Sep 21 '22 01:09

Artyom


The unicode codepoints you want to use are part of a private use area, i.e. every font manufacturer is free to put whatever character they like at whatever position. The font you used to look up the arrow characters is simply a different font than the one used for displaying the button text. If the button text maps \uE318 and \uE313 to some Chinese (?) graphem, then that's not wrong, just different.

like image 39
nd. Avatar answered Sep 20 '22 01:09

nd.


Although multiple people have made the argument you should avoid using these codepoints because you can't rely on the users' systems having a font which displays these characters, the reason you're getting the wrong characters in your example case has been entirely missed. All of the symbols you are trying to draw are in the "private use area" which means that the symbols involved will potentially be different in every single font.

The Unicode standard states:

Private Use Area (E000-F8FF) * The Private Use Area does not contain any character assignments, consequently no character code charts or namelists are provided for this area.

If you embed the particular font you want to use to insure you can use these codepoints, that's fine. But that does mean you should, indeed, use the \u#### notation in your code, because embedding the characters as Unicode directly means the source won't make sense unless somebody views it in the correct font.

All in all, it's probably better to use icons unless you already have a symbol font you think is simply far superior to any graphical work you would otherwise do.

like image 22
Conspicuous Compiler Avatar answered Sep 21 '22 01:09

Conspicuous Compiler