I am trying to show a success message gif from my javaFx application.
public static void successGif() {
int size = 400;
ImageView splash = new ImageView(new Image("file:src/main/resources/img/success3.gif"));
splash.setStyle("-fx-background-color: transparent;");
splash.setFitWidth(size);
splash.setFitHeight(size);
splash.setPickOnBounds(true);
Pane splashLayout = new Pane();
splashLayout.getChildren().add(splash);
final Stage initStage = new Stage();
Scene successScene = new Scene(splashLayout, size, size);
successScene.setFill(Color.TRANSPARENT);
initStage.initStyle(StageStyle.TRANSPARENT);
initStage.setWidth(size);
initStage.setHeight(size);
initStage.setScene(successScene);
initStage.show();
new Thread(() -> {
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
Platform.runLater(initStage::close);
}).start();
}
The above function can create a popup with a gif successfully. for now, I tried calling this function through a button in my application and the background of the popup is still white. But when I tested the same function by calling it in the start() function of the application, it works as expected. how can I fix this issue?
I need to call this function inside my application on many occasions.
How to make the background transparent.
The following is the gif in case you need to try, Thanks.
