启动 JavaFX 应用程序是通过调用Application.launch()
, 来完成的LauncherImpl#launchApplication
。
在 中launchApplication
,使用具有以下签名的参数调用私有 方法: launchApplication
preloaderClass
public static void launchApplication(final Class<? extends Application> appClass,
final Class<? extends Preloader> preloaderClass,
final String[] args)
现在preloader
类是您调用对话框的地方。
只需调用您的对话框并将您的其他功能放在这里:
public class MyPreloader extends Preloader {
private Stage preloaderStage;
@Override
public void start(Stage primaryStage) throws Exception {
this.preloaderStage = primaryStage;
VBox loading = new VBox(20);
loading.setMaxWidth(Region.USE_PREF_SIZE);
loading.setMaxHeight(Region.USE_PREF_SIZE);
loading.getChildren().add(new ProgressBar());
loading.getChildren().add(new Label("Please wait..."));
BorderPane root = new BorderPane(loading);
Scene scene = new Scene(root);
primaryStage.setWidth(800);
primaryStage.setHeight(600);
primaryStage.setScene(scene);
primaryStage.show();
}
@Override
public void handleStateChangeNotification(StateChangeNotification
stateChangeNotification) {
if (stateChangeNotification.getType() == Type.BEFORE_START) {
preloaderStage.hide();
}
}
}
然后将其传递给launchApplication
方法。
And just perfect!
Enjoy!