How can I access a Controller class in JavaFx 2.0?

后端 未结 4 703
滥情空心
滥情空心 2020-12-15 22:30

Recently I was programming a software with JavaFx2.0,but I met with a big problem,that is - How can I access a Controller class? For every controller class with the same cla

4条回答
  •  悲哀的现实
    2020-12-15 22:59

    I use the following :

    URL location = getClass().getResource("MyController.fxml");
    
    FXMLLoader fxmlLoader = new FXMLLoader();
    fxmlLoader.setLocation(location);
    fxmlLoader.setBuilderFactory(new JavaFXBuilderFactory());
    
    Parent root = (Parent) fxmlLoader.load(location.openStream());
    

    In this way fxmlLoader.getController() is not null

提交回复
热议问题