Accessing FXML controller class

后端 未结 4 1207
再見小時候
再見小時候 2020-11-22 07:51

I would like to communicate with a FXML controller class at any time, to update information on the screen from the main application or other stages.

Is this possible

4条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-22 08:12

    On the object's loading from the Main screen, one way to pass data that I have found and works is to use lookup and then set the data inside an invisible label that I can retrieve later from the controller class. Like this:

    Parent root = FXMLLoader.load(me.getClass().getResource("Form.fxml"));
    Label lblData = (Label) root.lookup("#lblData");
    if (lblData!=null) lblData.setText(strData); 
    

    This works, but there must be a better way.

提交回复
热议问题