简体   繁体   English

stage.setIconify(true)不适用于未装饰的舞台

[英]stage.setIconify(true) doesn't work with undecorated stage

I have an undecorated FXML stage. 我有一个未经修饰的FXML阶段。 I created a button to minimize window and created an event for it in Controller class in initialize method. 我创建了一个用于最小化窗口的按钮,并在initialize方法的Controller类中为其创建了一个事件。

minimizeBtn.setOnAction(e -> {


            Stage stage = (Stage)((Button)e.getSource()).getScene().getWindow();
            stage.setIconified(true);
            System.out.println(stage.isIconified());
        });

Problem: 问题:

isIconified() returns true , while nothing happens to window visually. isIconified()返回true ,而视觉上没有任何变化。

If I switch from UNDECORATED to default my custom button perfectly works. 如果我从UNDECORATED切换到默认设置,则我的自定义按钮可以正常使用。

Same problem for me on both MacOS High Sierra and Mojave, with jdk 11.0.2 and JavaFX 12.0.1 There's the example code to reproduce the issue. 在MacOS High Sierra和Mojave上,对于jdk 11.0.2和JavaFX 12.0.1来说,我遇到同样的问题。有示例代码可以重现该问题。
Note that without setting the UNDECORATED style to the stage the problem doesnt' happen. 请注意,如果未将UNDECORATED样式设置为舞台,则不会发生此问题。
On Windows the behaviour is correct no matter what the stage style is. 在Windows上,无论舞台样式是什么,行为都是正确的。

public class DemoApplication extends Application {

  @Override
  public void start(Stage primaryStage) {
      Button minimize = new Button("MINIMIZE");
      minimize.setOnAction(event -> primaryStage.setIconified(true));
      primaryStage.initStyle(StageStyle.UNDECORATED);

      Scene scene = new Scene(new StackPane(minimize));
      primaryStage.setTitle("JavaFX App");
      primaryStage.setWidth(960);
      primaryStage.setHeight(600);
      primaryStage.setScene(scene);
      primaryStage.show();
  }

  public static void main(String[] args) {
      launch(args);
  }

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM