modal JavaFX stage initOwner prevents owner from resizing, bug?

匿名 (未验证) 提交于 2019-12-03 01:39:01

问题:

If I open another JavaFX (modal) Stage, and set its owner as the original Stage, then the original Stage can't be resized, using the windows drag widget on the bottom right hand corner of the window

I see this in Linux but don't own windows or MacOS so can't test it elsewhere...

here is a minimal example

import javafx.stage.*; import javafx.scene.*; import javafx.event.*; import javafx.application.*; import javafx.scene.layout.*; import javafx.scene.control.*;  public class HelloWorld extends Application {     static Stage newStage;      @Override     public void start(Stage primaryStage)     {         Button btn = new Button();         btn.setText("open window");         btn.setOnAction(new EventHandler<ActionEvent>()         {             @Override             public void handle(ActionEvent event)             {                 if (newStage==null)                 {                     Button newBtn = new Button("Close window");                     newBtn.setOnAction(new EventHandler<ActionEvent>()                     {                         @Override                         public void handle(ActionEvent event)                         {                             //newStage.hide(); // either or                             newStage.close();                         }                      });                     newStage = new Stage();                     newStage.initModality(Modality.WINDOW_MODAL);                      newStage.initOwner(primaryStage);    // BUG doing this, makes main window fixed size                     newStage.initStyle(StageStyle.DECORATED);                     StackPane newRoot = new StackPane();                     newRoot.getChildren().add(newBtn);                     Scene newScene = new Scene(newRoot,200,160);                     newStage.setScene(newScene);                  }                 newStage.show();             }         });          StackPane root = new StackPane();         root.getChildren().add(btn);          Scene scene = new Scene(root, 300, 250);          primaryStage.setTitle("Hello World!");         primaryStage.setScene(scene);         primaryStage.show();     }      public static void main(String[] args)     {         launch(args);     } } 

回答1:

This is a confirmed Java bug. Looks like it's targeted for fixing in Java 10 sometime.

http://bugs.java.com/bugdatabase/view_bug.do?bug_id=8140491

That said, I'd love a workaround if someone has one.

Edit: one workaround I've found, ugly as it is, is that you can hide and show the owner stage after hiding the modal child stage. That re-enables resizing. You see the stage disappear and reappear, though, which is messy.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!