Issue
To use material design icons I did the following:
1.Downloaded ttf font from https://materialdesignicons.com/
2.in my css file I added:
@font-face {
src: url('fonts/materialdesignicons-webfont.ttf');
}
.icon {
-fx-font-size: 15px;
-fx-font-family: 'Material Design Icons';
}
3.Here https://pictogrammers.github.io/@mdi/font/6.5.95/ I copied the first icon ( mdi-account-lock-open with codepoint F1960) and pasted this icon in my Java code:
4.After that I added icon
class to button
and everything is ok - I have a button with an icon.
The only problem is that in my java code I can't see what icon I use - I have everywhere empty rectangles
. If it is possible, I would like to add icon using codepoints, for this example codepoint F1960
. I tried
private final Button button = new Button("\uF1960");
but it didn't work. Could anyone say how to do it?
Solution
Java characters are UTF-16 values. You cannot directly embed U+F1960 in a String, because Unicode \u
escapes must be followed by exactly four hex digits.
Characters with codepoint values above FFFF are called supplementary characters. UTF-16 represents such a character using a surrogate pair, which is a sequence of two characters from a reserved section of the Unicode repertoire.
You can represent U+F1960 in a String literal as its surrogate pair: "\udb86\udd60"
An alternative approach that’s easier to remember is String.format("%c", 0xF1960)
. The underlying java.util.Formatter is documented as allowing an Integer argument for %c
, and unlike characters, an Integer can be larger than 16 bits.
Answered By - VGR
Answer Checked By - David Goodson (JavaFixing Volunteer)