java.lang.Object
org.jhotdraw8.fxbase.fxml.AsyncFxmlLoader
Loads an FXML file asynchronously.
Note that this loader can only be used for FXML files, which do not instantiate windows (for example FXML files with Tooltips can't be loaded).
- Author:
- Werner Randelshofer
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic CompletionStage<javafx.fxml.FXMLLoader> Asynchronously loads the specified FXML file on the common fork-join pool, and returns a completion stage with the FXMLLoader.static CompletionStage<javafx.fxml.FXMLLoader> load(URL location, @Nullable ResourceBundle resources, Executor executor) Asynchronously loads the specified FXML file on the specified executor, and returns a completion stage with the FXMLLoader.static CompletionStage<javafx.fxml.FXMLLoader> load(URL location, ResourceBundle resources)
-
Constructor Details
-
AsyncFxmlLoader
public AsyncFxmlLoader()
-
-
Method Details
-
load
Asynchronously loads the specified FXML file on the common fork-join pool, and returns a completion stage with the FXMLLoader.- Parameters:
location- the location of the FXML file- Returns:
- the FXMLLoader.
-
load
-
load
public static CompletionStage<javafx.fxml.FXMLLoader> load(URL location, @Nullable ResourceBundle resources, Executor executor) Asynchronously loads the specified FXML file on the specified executor, and returns a completion stage with the FXMLLoader.You can then get the root and the controller of the loaded scene from the FXMLLoader.
Example usage:
// Load a menu bar asynchronously and add it to the top of a border pane. BorderPane borderPane = new BorderPane(); AsyncFXMLLoader.load(MainApp.class.getResource("MainMenuBar.fxml")) .whenComplete((loader, throwable) -> { if (throwable != null) { // Loading failed! Put a placeholder into the menu bar. borderPane.setTop(new Label(throwable.getMessage())); Logger.getLogger(getClass().getName()).log(Level.WARNING,"Unexpected Exception.",throwable); } else { // Loading succeeded. borderPane.setTop(loader.getRoot()); loader.>MainMenuBarController<getController().setFileController(fileController); return loader.getController(); } });- Parameters:
location- the location of the FXML fileresources- the resource file for internationalized texts in the FXML fileexecutor- the executor on which the task should be executed- Returns:
- the FXMLLoader.
-