public void btnAddDataClicked(ActionEvent actionEvent) { currentUser = (Users)btnAddData.getParent().getScene().getWindow().getUserData(); System.out.println(currentUser); } 

In this code, using the button object, I get getParent and the object I need in getUserData, I’m wondering how to get it during initialization:
@Override public void initialize(URL location, ResourceBundle resources) {

Inside this method, I did not find a suitable object to get getParent.
I tried many things, and all-powerful Google did not help.
PS Thanks in advance for your help!

    1 answer 1

    During the call to the initialize method you will not be able to get the scene (theoretically you can, but it will be null). Because the scene is not yet initialized.

    You either need to wait for the scene to appear, and take window and userData from it, or store user data in some other place.