In my UI, I have a Label that displays information when the user performs some tasks. This is a Spring/Hibernate/JavaFx application and all operations are currently performed in the JavaFx thread and last up to a few seconds max (like loading/saving data from a database). I would like to have something looking like this:
In the initialize method of my controller class
taskLabel.textProperty().bind(dataService.taskProperty());
In the DataService class :
public void saveData(Data someData) {
taskProperty.set("Saving data");
databaseService.saveData(someData);
taskProperty.set("Waiting");
}
public Data loadData() {
Data result = null;
taskProperty.set("Loading data");
result = databaseService.loadData();
taskProperty.set("Waiting");
return result;
}
These tasks take a few seconds, but the Label taskLabel only shows Waiting. I tried to use Platform.runLater, but I'm pretty sure even if dataService and databaseService are Spring services, their operations are still performed in the JavaFx thread (i never specified otherwise).
What's the proper way of doing this ?
Thanks in advance for your answers.