我遇到以下问题:如果我在其FXML文件中将Labels文本设置为Unicode字符,它将正确显示:
<Label alignment="TOP_CENTER" minHeight="140.0" minWidth="500.0" text="♧" ...>
正确显示
但是,如果我尝试使用label.setText设置这个标签,就会显示unicode序列本身:
label.setText("♧");
仅unicode字符串
我现在的问题是:如何让FXML在运行时显示unicode字符?
找到的解决方案:
private String fromUnicode(int unicode){
return new String(Character.toChars(unicode));
}
slabel.setText(fromUnicode(0x2664));