Java FX changing value of Label from different scene

后端 未结 3 461
孤街浪徒
孤街浪徒 2021-01-24 12:39

I have two scenes. The first scene invokes second scene using the following code.

@FXML
private void confirmation(ActionEvent event) throws IOException{
 Stage c         


        
3条回答
  •  后悔当初
    2021-01-24 13:23

    Assuming that you have a controller called:confirmation_controller.java'. inside that controller, you have a public method getProceedLabel() that returns a reference for the label called Proceed. you can try the following code:

     Stage confirmation_stage;
     Parent confirmation;
     confirmation_stage=new Stage();
     FXMLLoader loader = new FXMLLoader(getClass().getResource("Confirmation.fxml"));
     confirmation = loader.load();
     confirmation_controller controller = loader.getController();
     Label label = controller.getProceedLabel();
     label.setText("..."):
     confirmation_stage.setScene(new Scene(confirmation));
     confirmation_stage.initOwner(generate_button.getScene().getWindow());
     confirmation_stage.show();
    

提交回复
热议问题