【问题标题】:JavaFx ImageView SplashScreen not workingJavaFx ImageView SplashScreen 不工作
【发布时间】: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;
    }

}

【问题讨论】:

    标签: java image javafx-2 png


    【解决方案1】:

    尝试使用StageStyle.UNDECORATED 而不是StageStyle.TRANSPARENT。另外,我不确定您是否必须在新图像中指定一个新文件才能实例化 ImageView。尝试仅使用图像文件名。喜欢,ImageView splashImage = new ImageView("Splash.png");

    【讨论】:

      猜你喜欢
      • 2015-06-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多