It sounds like what your looking for is a binding of your label to a int type variable. You can accomplish this with
labelFXid.textProperty().bind(value.asString());
where value is an IntegerProperty declared in your controller class and labelFXid is the FXid assigned to your label in the FXML document. You can find a good example of this from Uluk Biy's solution to a similar question. In that example, he was binding a label directly from the FXML file. I had better luck keeping the code in the controller as in the example below.
FXMLDocument.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>
<AnchorPane id="AnchorPane" prefHeight="200" prefWidth="320" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="labelupdater.FXMLDocumentController">
<children>
<Button fx:id="button" layoutX="126" layoutY="90" onAction="#handleButtonAction" text="Click Me!" />
<Label fx:id="label" alignment="CENTER" layoutX="126" layoutY="120" minHeight="16" minWidth="69">
<font>
<Font size="24.0" />
</font></Label>
</children>
</AnchorPane>
FXMLDocumentController.java
package labelupdater;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.beans.property.*;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Label;
public class FXMLDocumentController implements Initializable {
private IntegerProperty counter;
public int getCounter() {
return counter.get();
}
public void setCounter(int value) {
counter.set(value);
}
public IntegerProperty counterProperty() {
return counter;
}
@FXML
private Label label;
@FXML
private void handleButtonAction(ActionEvent event) {
setCounter(getCounter() + 1);
}
@Override
public void initialize(URL url, ResourceBundle rb) {
counter = new SimpleIntegerProperty(0);
label.textProperty().bind(counter.asString());
}
}
The end result is that every time the button is clicked setCounter(getCounter() + 1)
increments the value of the variable counter by one and the label is automatically updated to display the new value. The counter variable and binding are declared in the initialize of FXMLDocumentController.
edit:typo correction