Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8114070

Closing the last window then immediately opening another one should not cause application exit

    XMLWordPrintable

Details

    Description

      Consider this test program:

      public class CloseBug extends Application {
          public static void main(String[] args) {
              launch(args);
          }

          @Override public void start(final Stage primaryStage) throws Exception {
              Button switchOver = ButtonBuilder.create().text("Switch").onAction(new EventHandler<ActionEvent>() {
                  @Override public void handle(ActionEvent event) {
                      primaryStage.close();
                      Stage other = StageBuilder.create().height(100).width(100).visible(true).build();
                  }
              }).build();
              StageBuilder.create().height(200).width(200).scene(new Scene(new Group(switchOver))).visible(true).applyTo(primaryStage);
          }
      }

      When you hit the "Switch" button, it closes the original stage but, before returning to the event loop, creates another one. Unfortunately, the application framework has noticed that the window count dropped to 0, and therefore decides to exit, even if new windows can be created. The same thing happens if the creation of the second window is wrapped inside Platform.runLater.

      The intent of the exit detection logic is to determine when no more JavaFX activity can reasonably be expected to happen. From the e-mail discussions I have seen, this is supposed to cover at least the Platform.runLater case, and I think it should cover a fortiori the case above where a new window is created within the same event dispatch. I think the logic should essentially be to detect when there are no more windows AND no more outstanding events, where pending runLaters are considered to be outstanding events. In the code above, the button's onAction event has not been fully handled, so the fact that the window count drops briefly to zero should not imply exit.

      Attachments

        Issue Links

          Activity

            People

              kcr Kevin Rushforth
              emcmanuswse Eamonn McManus (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported: