JavaFX 1 FXML File with Multiple Different Controllers?

后端 未结 1 1641
不思量自难忘°
不思量自难忘° 2020-12-31 23:02

There are two different stages in my application that are help screens that use the same FXML file. Rather than create 2 FXML files, I would like to use just one and have t

相关标签:
1条回答
  • 2020-12-31 23:37

    You can remove the fx:controller="" assignment from the FXML file and assign the controller via the FXMLLoader during the load.

    FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("Your.fxml"));
    fxmlLoader.setController(this);
    
    try
    {
        fxmlLoader.load();
    }
    catch (IOException exception)
    {
        throw new RuntimeException(exception);
    }
    

    Check out the Introduction to FXML section on custom components.

    0 讨论(0)
提交回复
热议问题