J'essaie de faire apparaître mon écran de démarrage JavaFX Preloader avant mon application. J'utilise Eclipse IDE et quand je clique sur "Exécuter", la moitié du temps l'écran de démarrage s'affichera correctement et l'autre moitié du temps j'obtiendrai un écran gris ou noir au lieu d'où l'image devrait être.Pourquoi mon préchargeur JavaFX apparaît-il parfois gris/noir et d'autres fois il charge correctement?
Je ne sais pas quel est le problème pour que l'affichage ne s'affiche correctement parfois.
SplashController:
public class SplashController extends Preloader {
private static final double WIDTH = 676;
private static final double HEIGHT = 227;
private Stage preloaderStage;
private Label progressText;
private Pane splashScreen;
public SplashController() {}
@Override
public void init() throws Exception {
ImageView splash =
new ImageView(new Image(Demo.class.getResource("pic.png").toString()));
progressText =
new Label("VERSION: " + getVersion() + " ~~~ Loading plugins, please wait...");
splashScreen = new VBox();
splashScreen.getChildren().addAll(splash, progressText);
progressText.setAlignment(Pos.CENTER);
}
@Override
public void start(Stage primaryStage) throws Exception {
this.preloaderStage = primaryStage;
Scene splashScene = new Scene(splashScreen);
this.preloaderStage.initStyle(StageStyle.UNDECORATED);
final Rectangle2D bounds = Screen.getPrimary().getBounds();
this.preloaderStage.setScene(splashScene);
this.preloaderStage.setX(bounds.getMinX() + bounds.getWidth()/2 - WIDTH/2);
this.preloaderStage.setY(bounds.getMinY() + bounds.getHeight()/2 - HEIGHT/2);
this.preloaderStage.show();
}
}
Et puis dans ma classe principale Demo J'ai simplement:
public class Demo extends Application {
@Override
public void start(Stage stage) throws Exception {
FXMLLoader loader = new
FXMLLoader(Demo.class.getResource("FXMLDocument.fxml"));
GridPane root = loader.load();
--------other app code here---------
}
public static void main(String[] args) {
LauncherImpl.launchApplication(Demo.class, SplashController.class, args);
}
}
Merci! Oui le problème était que j'ai eu un long processus en cours sur le fil JavaFX :) – chip
OK, chanceux devinez :-), je viens de faire le commentaire dans une réponse. – jewelsea