Sunday, December 10, 2017

JAVAFX - How get Controller after form load

When you want to call some method on loaded form, you need at first controller:
public class App extends Application {
    
  @Override
  public void start( Stage stage ) throws Exception {
        
    /* load form FXMLMain */
    
    FXMLLoader fLoader = new FXMLLoader( getClass().getResource( "FXMLMain.fxml" ) );
    Parent root = fLoader.load();

    /* ..get its controller..and call some method */

    FXMLMain controller = fLoader.getController();
    controller.prepare( this );
    ...
  }

No comments:

Post a Comment