user3063514
user3063514

Reputation: 1

How to assign label text to a determined variable on JavaFX

I'm making a Java program in which I'm using JavaFX for a more polished GUI. Problem is, I have to assign a variable to a certain label (text), so that when I change the variable, the label text also changes.

On Swing this is easy to do, but in JavaFX you use fxml to build your user interface. How do I assign a variable to this label, since the variable is obviously from a .java class and the file where I make these changes is a fxml?

This is the label code by the way

<Label fx:id="palavra" layoutX="424.0" layoutY="148.0" prefWidth="177.0" text="(this is where the variable must assign)">

Upvotes: 0

Views: 1050

Answers (1)

damat-perdigannat
damat-perdigannat

Reputation: 5950

Brian is right. When you assign a controller to your FXML file, annotate the Label called palavra with @FXML. Not necessarily "public static" though.

@FXML public Label palavra;

Upvotes: 3

Related Questions