You need to do this in an event handler method in your controller, not in the initialize() method. At the time the initialize method is called, the object loaded by the FXML file will (likely) not have been added to a window. So the controller will look something like: