【发布时间】:2016-02-24 23:24:48
【问题描述】:
我想使用 .png 图片通过 Preloader 和 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;
}
}
【问题讨论】: