Andrew Bystrov Andrew Bystrov - 1 year ago 119
Java Question

Fxml set styleclass from source

I have class with final static fields :

package com.a.b;

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

And I want to set styleClass property for button from this class. Inside fxml file, I do :

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

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

But I have got the error :

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

I try to write different versions, but always got a error.

How I can write styleClass ( or another attribute) via link from source?

Answer Source

Use <fx:constant>:

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

<Button fx:id="myBtn">
      <MyVars fx:constant="S1" />  //here error
      <MyVars fx:constant="S2" />
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download