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

"java.lang.IllegalStateException: The window has already been closed when " when redisplaying a second stage containing a ChoiceBox

    Details

      Description

      This is my very first time opening an issue so I apologize in advance if I am not completely following the correct protocol. I am almost certain someone will correct me. The bottom line is that I am taking my valuable time to bring this issue to someone's attention.

      I am creating a second stage to be used as a modal dialog box. This second stage contains a ChoiceBox and a simple close button (which hides the stage). I display this stage (dialog box), select an item from the choice box, and then click the close button. I then redisplay the stage and simply click the close button which causes the exception "java.lang.IllegalStateException: The window has already been closed at com.sun.glass.ui.Window.checkNotClosed(Unknown Source)". The second stage remains visible. The following code can be used to reproduce the problem

      <code>
      import javafx.application.Application;
      import javafx.event.ActionEvent;
      import javafx.event.EventHandler;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.control.ChoiceBox;
      import javafx.scene.layout.VBox;
      import javafx.stage.Modality;
      import javafx.stage.Stage;

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

      @Override
      public void start(final Stage primaryStage) throws Exception {
      final Button button = new Button("Launch modal dialog");
      button.setOnAction(new EventHandler<ActionEvent>() {
      public void handle(ActionEvent event) {
      final Stage stage = new Stage();
      final ChoiceBox<String> startTimeChoiceBox = new ChoiceBox<String>();
      startTimeChoiceBox.setPrefWidth(150.0);
      startTimeChoiceBox.setMaxWidth(150.0);
      startTimeChoiceBox.getItems().addAll("12:00 AM", "1:00 AM",
      "2:00 AM", "3:00 AM",
      "4:00 AM", "5:00 AM", "6:00 AM",
      "7:00 AM","8:00 AM",
      "9:00 AM", "10:00 AM", "11:00 AM",
      "12:00 PM", "1:00 PM",
      "2:00 PM", "3:00 PM", "4:00 PM",
      "5:00 PM", "6:00 PM",
      "7:00 PM", "8:00 PM", "9:00 PM",
      "10:00 PM", "11:00 PM");


      Button closeButton = new Button("Close");
      closeButton.setOnAction(new EventHandler<ActionEvent>() {

      public void handle(ActionEvent event) {
      stage.hide();
      }
      });

      VBox vb = new VBox();
      vb.getChildren().addAll(startTimeChoiceBox, closeButton);

      Scene scene1 = new Scene(vb);
      stage.initModality(Modality.APPLICATION_MODAL);
      // also tried WINDOW_MODAL
      stage.initOwner(primaryStage);
      stage.setScene(scene1);
      stage.setVisible(true);
      }
      });
      VBox vBox = new VBox();
      vBox.getChildren().add(button);
      Scene scene = new Scene(vBox, 200, 200);
      primaryStage.setScene(scene);
      primaryStage.setVisible(true);
      }
      }
      </code>

        Attachments

          Activity

            People

            • Assignee:
              thor Thor Johannesson (Inactive)
              Reporter:
              duke J. Duke (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported: