[英]Start the application window maximized in JavaFX FXML not working properly
我希望我的 Javafx FXML 應用程序開始最大化,所以我在我的階段使用了setMaximized(true)
方法。
該程序打開為最大化沒有問題,但問題是在窗口出現之前,在應用程序啟動時有一個小的黑色區域閃爍半秒。
我發現問題出在場景上,因為它試圖在它的 prefWidth 和 prefHeight 中打開,然后它會放大以適應舞台。 我該如何解決這個問題並使程序像普通程序一樣啟動?
這是我的 start() 方法:
@Override
public void start(Stage primaryStage) throws Exception{
Parent root = FXMLLoader.load(getClass().getResource("editor.fxml"));
primaryStage.setTitle("Simple Text Editor");
primaryStage.setScene((new Scene(root)));
primaryStage.setMaximized(true);
primaryStage.show();
}
我發現的唯一解決方法是:
@Override
public void start(Stage primaryStage) throws Exception{
Parent root = FXMLLoader.load(getClass().getResource("editor.fxml"));
primaryStage.setTitle("Simple Text Editor");
primaryStage.setScene(new Scene(root));
primaryStage.setMinWidth(450);
primaryStage.setMinHeight(300);
Screen screen = Screen.getPrimary();
Rectangle2D bounds = screen.getVisualBounds();
primaryStage.setWidth(bounds.getWidth());
primaryStage.setHeight(bounds.getHeight());
primaryStage.setMaximized(true);
primaryStage.show();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.