【发布时间】:2017-10-12 12:57:52
【问题描述】:
我正在尝试让我的 JavaFX Preloader 启动屏幕显示在我的应用程序之前。我正在使用 Eclipse IDE,当我单击“运行”时,一半的时间启动画面会正确显示,而另一半的时间我会得到一个灰色或黑色的屏幕,而不是图像应该在的位置。
我不确定是什么问题导致它有时只能正确显示。
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();
}
}
然后在我的主课 Demo 中,我只有:
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);
}
}
【问题讨论】:
-
谢谢!是的,问题是我在 JavaFX 线程上有一个长时间运行的进程 :)
-
好的,幸运的猜测:-),我刚刚将评论变成了答案。
标签: javafx preloader image-preloader