gpt4 book ai didi

javafx - 在 JavaFX 中使用 Unicode 字符

转载 作者:行者123 更新时间:2023-12-01 10:23:18 32 4
gpt4 key购买 nike

我已经玩了一段时间的 Swing 并且决定现在看看 FX。到目前为止,我发现与摆动相比,它更容易和更有趣,但我遇到了一个小的减速带,经过几个小时的环顾四周,我找不到解决方案。

当我尝试通过 fxml 文件添加它时,我无法使用\u 如果我不使用 fxml,它工作正常,但我想使用场景构建器,因为它更方便。
这是一小段代码:

<?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>

我不断收到的错误是

Caused by: javafx.fxml.LoadException: Invalid escape sequence.



不确定是否相关,但我正在使用 jdk1.8.0_131 & netbeans 8.2

如果有人能在这里指出我正确的方向,我将不胜感激。

最佳答案

FXML 是一个 XML,因此您需要使用 XML 转义:

<?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="&#x0644;&#x0627;&#x062B;&#x0627;&#x0646;&#x0649;" />
</children>
</AnchorPane>

话虽如此,如果您能够输入字符,则可以按原样插入它们。

另见: https://www.w3.org/International/questions/qa-escapes

关于javafx - 在 JavaFX 中使用 Unicode 字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49016202/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com