gpt4 book ai didi

java - Fxml 从源设置样式类

转载 作者:行者123 更新时间:2023-12-02 03:13:26 26 4
gpt4 key购买 nike

我有一个带有最终静态字段的类:

package com.a.b;

public class MyVars {
public static final String S1 = "s1";
public static final String S2 = "s2";
....
}

我想为此类中的按钮设置 styleClass 属性。在 fxml 文件中,我这样做:

<?import  com.a.b.MyVars?> // import my class

<Button fx:id="myBtn">
<styleClass>
<String fx:value=MyVars.S1 /> //here error
<String fx:value=MyVars.S2 />
</styleClass>
</Button>

但是我遇到了错误:

Message: Open quote is expected for attribute "fx:value" associated with an element type "String".

我尝试编写不同的版本,但总是出错。

如何通过源链接编写 styleClass (或其他属性)?

最佳答案

使用 <fx:constant> :

<?import  com.a.b.MyVars?> // import my class

<Button fx:id="myBtn">
<styleClass>
<MyVars fx:constant="S1" /> //here error
<MyVars fx:constant="S2" />
</styleClass>
</Button>

关于java - Fxml 从源设置样式类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40722817/

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