简体   繁体   中英

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

I have an undecorated FXML stage. I created a button to minimize window and created an event for it in Controller class in initialize method.

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.

If I switch from UNDECORATED to default my custom button perfectly works.

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.
Note that without setting the UNDECORATED style to the stage the problem doesnt' happen.
On Windows the behaviour is correct no matter what the stage style is.

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);
  }

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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