0

I created a PopUp with an extra FXML File and some Labels. Now I want to set the Labels, when the PopUp shows up, which does not work.

@FXML
private void handleButtonAction(ActionEvent event) throws 
        IOException, InterruptedException {
    Stage stage; 
    Parent root;
    if(event.getSource()==button) {
        stage = new Stage();
        root = FXMLLoader.load(getClass().getResource("popup.fxml"));
        stage.setScene(new Scene(root));
        stage.setTitle("New PopUp");
        stage.initModality(Modality.APPLICATION_MODAL);
        stage.initOwner(button.getScene().getWindow());
        label1.setText("test");
        stage.showAndWait();
    }
    else {
        stage=(Stage)back.getScene().getWindow();
        stage.close();
    }
} 

Do you have any hints where to set the label1 correctly? Thx

OttPrime
  • 1,878
  • 1
  • 15
  • 24
cartilage
  • 33
  • 6
  • Is `label1` part of `popup.fxml` or part of the owning stage? Is `label1` displaying any default text? – OttPrime May 08 '15 at 15:34
  • Create a method in the controller class for `popup.fxml` to set the label's text, and then just call that method on the controller. See http://stackoverflow.com/questions/14187963/passing-parameters-javafx-fxml/14190310#14190310 – James_D May 08 '15 at 16:45
  • @Ottprime label1 is part of popup.fxml, tried it with and without default text. I followed the steps mentioned in James_D post, but got an NullPointerException when setting the label from the initData method. – cartilage May 11 '15 at 08:22
  • found the problem, thx – cartilage May 11 '15 at 09:30

0 Answers0