JavaFx Label text = variable


I have a JavaFX GUI in an fxml file with its controller class defined. I have two text items that I want in that GUI, one tied to a variable whose value does not change until the user reloads the screen, the other I would think needs to be a StringProperty as it shows the running total of a column in my TableView. Because of what they are, I'm trying to use Label instead of a TextField as their display control.

I liked Sebastian's answer to this problem here:

Displaying changing values in JavaFx Label

however, when I try to use it I get a compile error that says:

cannot find symbol
   symbol: variable textProperty
   location: variable salesNoLabel of type Label

I'm not sure what I'm doing wrong, but to start with, my label text is initially set in the fxml file, so in my controller I just have its fx:id substituted for "myLabel" listed in Sebastian's answer:


where salesNoLabel is the fx:id of the label and sn is a string variable.

Not sure if you need to see more of my code to help me with this problem, but thanks in advance for checking it out.

Best Solution

Sebastian's answer had a syntax error, I edited it to fix it.

You need to invoke the textProperty() method on the label:


Note the addition of parentheses after the textProperty identifier to invoke the method.

Related Question