在JavaFX中使用Unicode字符 [英] Using Unicode characters with JavaFX
问题描述
我一直玩摇摆一段时间,现在决定退房。到目前为止,我发现与摇摆相比,使用起来更轻松,更有趣,但我遇到了一个小的减速带,经过几个小时的环顾四周,我找不到解决方案。
I've been playing around with swing for some time and decided to check out FX now. So far I'm finding it a lot easier and more fun to work with as compared to swing but I've run into a small speed bump and after hours of looking around I just can't find a solution.
当我尝试通过fxml文件添加它时,我无法使用\ u 如果我不使用fxml但我想要使用场景构建器,因为它更方便。
这是一小段代码:
I am unable to use \u when I try to add it through the fxml file It works fine if I don't use the fxml but I want to use the scene builder as it is more convenient. Here's the small piece of code:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane id="AnchorPane" prefHeight="200" prefWidth="320" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8.0.131" fx:controller="baitform.designDocController">
<children>
<Button fx:id="button" layoutX="126" layoutY="90" onAction="#handleButtonAction" text="Click Me!" />
<Label layoutX="145.0" layoutY="129.0" text="\u0644\u0627\u062B\u0627\u0646\u0649" />
</children>
</AnchorPane>
我一直遇到的错误是
引起:javafx.fxml.LoadException:转义序列无效。
Caused by: javafx.fxml.LoadException: Invalid escape sequence.
不确定是否相关,但我使用 jdk1.8.0_131 & netbeans 8.2
Not sure if relevant, but I'm using jdk1.8.0_131 & netbeans 8.2
如果有人能指出我正确的方向,我真的很感激。
If anyone could point me in the right direction here I'd really appreciate it.
推荐答案
FXML是一个XML,所以你需要使用XML转义:
FXML is an XML, and so you need to use XML escaping:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane id="AnchorPane" prefHeight="200" prefWidth="320" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8.0.131" fx:controller="baitform.designDocController">
<children>
<Button fx:id="button" layoutX="126" layoutY="90" onAction="#handleButtonAction" text="Click Me!" />
<Label layoutX="145.0" layoutY="129.0" text="لاثانى" />
</children>
</AnchorPane>
话虽如此,如果您能够输入字符,您可以按原样插入它们。
That being said, if you are able to input the characters, you can just insert them as is.
另请参阅: https: //www.w3.org/International/questions/qa-escapes
这篇关于在JavaFX中使用Unicode字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!