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

Pressing ESC in a nested alert closes self and parent alert

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 8u40
    • Fix Version/s: 9
    • Component/s: javafx
    • Labels:
    • Subcomponent:
    • CPU:
      x86
    • OS:
      os_x

      Backports

        Description

        FULL PRODUCT VERSION :
        $ java -version
        java version "1.8.0_60-ea"
        Java(TM) SE Runtime Environment (build 1.8.0_60-ea-b23)
        Java HotSpot(TM) 64-Bit Server VM (build 25.60-b22, mixed mode)

        ADDITIONAL OS VERSION INFORMATION :
        Darwin 14.4.0 Darwin Kernel Version 14.4.0: Thu May 28 11:35:04 PDT 2015; root:xnu-2782.30.5~1/RELEASE_X86_64 x86_64


        A DESCRIPTION OF THE PROBLEM :
        In a UI where a (parent) dialog spawns a child dialog (e.g., parent dialog is a configuration dialog and needs to allow the user to browse for a particular folder as part of that configuration), if the user chooses to exit the child dialog using the ESC keypress, both the child and parent dialogs are closed. This is not expected behavior. The ESC keypress should only affect the child dialog.

        This has only been run on OS X (see versions below), so it's not clear that this is a problem across all platforms.

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Run the provided code and pay attention to the instructions in the UI:



        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        Pressing ESC to close a dialog, even if it is spawned from another dialog, should only close the current dialog.
        ACTUAL -
        Pressing ESC to close a dialog spawned from another dialog closes the current dialog and the parent dialog.

        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        /**
         * As of at least JDK 1.8.0_60 early releases (maybe earlier, e.g. 1.8.0_40),
         * if you launch a dialog (e.g., file/dir chooser from a JavaFX Alert,
         * and the user presses ESC to close the dialog, the alert will also close.
         *
         * This is unexpected behavior.
         *
         * @author Paul Furbacher
         *
         */
        public class DemoApp extends Application {

            private static final String VBOX_STYLE = "-fx-padding: 12px; -fx-alignment: center";

            @Override
            public void start(Stage primaryStage) throws Exception {
                
                VBox vbox = new VBox(16);
                vbox.setStyle(VBOX_STYLE);
                Label label = new Label("Press button to launch dialog");
                Button button = new Button("Save ...");
                button.setOnAction(ae -> {
                    createAndShowDirChooser();
                });
                vbox.getChildren().addAll(label, button);
                
                primaryStage.setScene(new Scene(vbox));
                primaryStage.sizeToScene();
                primaryStage.show();
            }

            protected void createAndShowDirChooser() {
                Alert alert = new Alert(AlertType.INFORMATION); // or try other types, such as AlertType.CONFIRMATION.
                    // Except for AlertType.NONE, they all exhibit the problem.
                
                alert.setTitle("Demo Alert");
                Button browseButton = new Button("Browse...");
                browseButton.setOnAction(ae -> {
                    DirectoryChooser chooser = new DirectoryChooser();
                    chooser.showDialog(browseButton.getScene().getWindow());
                });
                VBox vbox = new VBox(16);
                vbox.setStyle(VBOX_STYLE);
                vbox.getChildren().addAll(
                    new Label("Press ESC in the directory chooser.\n\nUnexpected result: this dialog will also close!\n\n"), browseButton);
                alert.getDialogPane().setContent(vbox);
                Platform.runLater(() -> browseButton.requestFocus());
                alert.showAndWait();
            }

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

        ---------- END SOURCE ----------

        CUSTOMER SUBMITTED WORKAROUND :
        None, except perhaps rewriting the parent view to use a stage instead of an alert (dialog).

          Attachments

            Issue Links

              Activity

                People

                Assignee:
                jgiles Jonathan Giles
                Reporter:
                webbuggrp Webbug Group
                Votes:
                0 Vote for this issue
                Watchers:
                6 Start watching this issue

                  Dates

                  Created:
                  Updated:
                  Resolved: