toFront()方法不能在java fx中使用启动画面

时间:2018-01-11 12:39:15

标签: java javafx splash-screen

我想创建一个简单的戳,我有一个启动画面(就像一个adobe一样),可以实现多屏应用

这样做是我的主要课程ScreensFramework

public class ScreensFramework extends Application {


public static String screen1ID = "main";
public static String screen1File = "Screen1.fxml";
public static String screen2ID = "screen2";
public static String screen2File = "Screen2.fxml";
public static String screen3ID = "screen3";
public static String screen3File = "Screen3.fxml";

private Pane splashLayout;
private Stage mainStage;


@Override
public void init() {
    ImageView splash = new ImageView(new Image("http://www.versluis.com/wp-content/uploads/2013/08/CCsplash-610x520.png"));
    splashLayout = new VBox();
    splashLayout.getChildren().addAll(splash);
    splashLayout.setEffect(new DropShadow());
}

@Override
public void start(Stage primaryStage) {     
    showSplash(primaryStage);

    Timeline timeline = new Timeline(new KeyFrame(
            Duration.millis(2500),
            ae -> showMainStage(primaryStage)));
    timeline.play();
}

private void showMainStage(Stage initStage) {
    initStage.hide();
    mainStage = new Stage(StageStyle.DECORATED);
    mainStage.setTitle("My Test");
    mainStage.setIconified(true);

    ScreensController mainContainer = new ScreensController();

    mainContainer.loadScreen(ScreensFramework.screen1ID, ScreensFramework.screen1File);
    mainContainer.loadScreen(ScreensFramework.screen2ID, ScreensFramework.screen2File);
    mainContainer.loadScreen(ScreensFramework.screen3ID, ScreensFramework.screen3File);

    mainContainer.setScreen(ScreensFramework.screen1ID);

    Group root = new Group();
    root.getChildren().addAll(mainContainer);
    Scene scene = new Scene(root);
    mainStage.setScene(scene);
    mainStage.show();
    mainStage.toFront();

}

private void showSplash(Stage initStage) {
    Scene splashScene = new Scene(splashLayout);
    initStage.initStyle(StageStyle.UNDECORATED);
    initStage.initStyle(StageStyle.TRANSPARENT);
    splashScene.setFill(Color.TRANSPARENT);
    initStage.setScene(splashScene);
    initStage.show();
}

/**
 * The main() method is ignored in correctly deployed JavaFX application.
 * main() serves only as fallback in case the application can not be
 * launched through deployment artifacts, e.g., in IDEs with limited FX
 * support. NetBeans ignores main().
 *
 * @param args the command line arguments
 */
public static void main(String[] args) {
    launch(args);
}

}

除了一件事以外,事情都很顺利:

mainStage.toFront();

当调用此方法时,我的图标以橙色闪烁,但窗口不在前面。所以基本上我有我的启动画面,如果我不在Windows图标上单击我的自我,那就没有了。

它来自哪里?

0 个答案:

没有答案