0

I'm already able to create and show a new window that uses the itemPopup.fxml file. My PrimaryStage uses the mainWindow.fxml file.

But my problem is that when I run the code to display the itemPopup window an error occurs when trying to change the itemLabel that is located in the itemPopop.fxml file. I have no problem changing labels from the mainWindow.fwml file.

@FXML
Label itemLabel

public void showItemPopup() throws Exception {
    FXMLLoader fxmlLoader = new 
    FXMLLoader(getClass().getResource("itemPopup.fxml"));
    Parent root1 = fxmlLoader.load();
    Stage stage = new Stage();
    stage.initStyle(StageStyle.UNDECORATED);
    stage.setScene(new Scene(root1));
    stage.show();
    itemLabel.setText("TEST");
}
Wouter A
  • 23
  • 6
  • Whatever object you are calling `showItemPopup` on, it is definitely not the controller for `itemPopup.fxml`, which is created when you call `fxmlLoader.load()`. So `itemLabel` will not be initialized when you try to set its text. You need to call `itemLabel.setText(...)` in the actual controller. Probably what you want to do is explained in https://stackoverflow.com/q/14187963 – James_D Mar 25 '18 at 22:17
  • @James_D Thank you! doing like you said worked, I had to load() after setting the controller. The link is also interesting. – Wouter A Mar 25 '18 at 23:08

0 Answers0