[英]JavaFx ImageView SplashScreen not working
我想使用.png圖片通過預加載器和ImageView作為初始屏幕顯示,但.png圖像未顯示。 (.png圖像與下面指定的類位於同一目錄中。)
import java.io.File;
import javafx.application.Preloader;
import javafx.scene.Scene;
import javafx.scene.effect.DropShadow;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
public class Splash extends Preloader {
private Stage splashStage;
@Override
public void start(Stage primaryStage) throws Exception {
this.splashStage = primaryStage;
this.splashStage.setWidth(800);
this.splashStage.setHeight(300);
this.splashStage.setResizable(false);
this.splashStage.initStyle(StageStyle.TRANSPARENT);
Pane pane = new Pane();
Scene scene = new Scene(pane, 800, 300);
ImageView splashImage = new ImageView(new Image(new File("Splash.png").toURI().toString()));
splashImage.setEffect(new DropShadow(4, Color.GREY));
pane.getChildren().add(splashImage);
splashImage.setFitWidth(800);
splashImage.setFitHeight(800);
this.splashStage.setScene(scene);
this.splashStage.show();
Thread.sleep(3000);
}
@Override
public void handleStateChangeNotification(StateChangeNotification stateChangeNotification) {
if(stateChangeNotification.getType() == StateChangeNotification.Type.BEFORE_START) {
splashStage.hide();
}
}
public Stage getSplashScreen() {
return this.splashStage;
}
}
嘗試使用StageStyle.UNDECORATED
而不是StageStyle.TRANSPARENT
。 另外,我不確定您是否必須在新Image中指定一個新文件來實例化ImageView。 嘗試僅使用圖像文件名。 就像ImageView splashImage = new ImageView("Splash.png");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.