How to return value from a stage before closing it?

前端 未结 4 648
遥遥无期
遥遥无期 2020-11-27 23:26

First of all, sorry for the bad english.

Here is the case:

I have a \"main stage\" where i press a button to open a \"second stage\" where i have a table, th

4条回答
  •  余生分开走
    2020-11-28 00:24

    You can write your own Stage class with a return statement.

    public class MyStage extends Stage {
       public String showAndReturn(myFXControll controll) {     
          super.showAndWait();
          return controll.getReturn();
       }
    } 
    

    After that you have to define a return function to your controller.

    public class TableFilterControll implements Initializable {
        @Override
        public void initialize(URL arg0, ResourceBundle arg1) {
        }
        public String getReturn() {
            return "I'm a nice return value"; //return what you want controlled by your controller class
        }
    }
    

    Now you can controll your return from the parent controller.

    String retValue=myStage.showAndReturn(childControll);
    
    System.out.println(retValue);
    

    I think this is a good solution for clean code. And you can style your FXML with Screne Builder.

提交回复
热议问题