Fxml 从源代码中设置样式类
Fxml set styleclass from source
我有 class 最终静态字段:
package com.a.b;
public class MyVars {
public static final String S1 = "s1";
public static final String S2 = "s2";
....
}
并且我想为此 class 中的按钮设置样式类 属性。在 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".
我尝试写不同的版本,但总是出错。
如何通过 link 从源代码编写 styleClass(或其他属性)?
<?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>
我有 class 最终静态字段:
package com.a.b;
public class MyVars {
public static final String S1 = "s1";
public static final String S2 = "s2";
....
}
并且我想为此 class 中的按钮设置样式类 属性。在 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".
我尝试写不同的版本,但总是出错。
如何通过 link 从源代码编写 styleClass(或其他属性)?
<?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>