A separate thread gets Controller through below line segment code
FXMLLoader loader = new FXMLLoader();
loader.setLocation(getClass().getResource("FXMLDocument.fxml"));
try
{
loader.load();
} catch (Exception ex)
{
System.out.println("Error loading");
}
FXMLDocumentController controller = loader.getController();
Controller contains a method dynamicUpdate(String data)
, Now I am calling this method from the thread where I have got the controller as follow.
controller.dynamicUpdate("hello from the thread"+count);
now here is the method in the controller: FXMLDocumentController
:
public void dynamicUpdate(String data)
{
helloLabel.setText(data);
}
Where helloLabel is the id of the label and in the controller it's an instance variable In xml it's inside pane:
<Label fx:id="helloLabel" layoutX="182.0" layoutY="179.0" prefHeight="43.0" prefWidth="259.0" text="sdadsadasdsadasd" />
in Controller it's:
@FXML
public Label helloLabel;
The issue is the method is being called and the console outputs are being print on the console but the text label is not being updated and neither any exception is being thrown. Any help, any reading will be very great ! Thank you