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

FileChooser: dialog is not modal

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Duplicate
    • Affects Version/s: fx2.0
    • Fix Version/s: fx2.0
    • Component/s: javafx
    • Environment:

      Windows 7 64bit, JDK 7 EA b147 64bit, JavaFX b36 64bit

      Description

      It appears that, on Windows, FileChooser is not modal by default and does not provide an API to set its modality relative to its parent Stage.

      It's possible to interract with the content of the scene of the parent Stage.

      It's even posible to close the parent Stage without closing the FileChooser dialog first and the program keeps running as long as the FileChooser dialog is open.

      In the case of a file opening dialog this may provoke an IllegalStateException as it looks like the JavaFX Application Thread was stopped when the main Stage was closed (or stopped when the dialog was closed).

      Complete message is: java.lang.IllegalStateException: Service must only be used from the FX Application Thread

      Code that provokes that is:

          /**
           * Called whenever the open document menu item is clicked.
           */
          public void onOpenDocument() {
              File directory = new File(prefs.get("last.directory", System.getProperty("user.dir"))); // NOI18N.
              FileChooser dialog = new FileChooser();
              dialog.setInitialDirectory(directory);
              ExtensionFilter plotRepFilter = new ExtensionFilter(I18N.getString("PLOT_REP_FILTER_DESCRIPTION"), "*.rep"); // NOI18N.
              ExtensionFilter fitFilter = new ExtensionFilter(I18N.getString("FIT_FILTER_DESCRIPTION"), "*.fit"); // NOI18N.
              ExtensionFilter frqFilter = new ExtensionFilter(I18N.getString("FRQ_FILTER_DESCRIPTION"), "*.frq"); // NOI18N.
              ExtensionFilter anyFilter = new ExtensionFilter(I18N.getString("ANY_FILTER_DESCRIPTION"), "*"); // NOI18N.
              dialog.getExtensionFilters().addAll(plotRepFilter, frqFilter, fitFilter, anyFilter);
              File file = dialog.showOpenDialog(stage);
              if (file == null) {
                  return;
              }
              // Save for later.
              prefs.put("last.file", file.getAbsolutePath()); // NOI18N.
              prefs.put("last.directory", file.getParentFile().getAbsolutePath()); // NOI18N.
              //
              openFileAsync(file);
          }

          private void openFileAsync(final File file) {
              final PlotRepLoaderService repLoaderService = new PlotRepLoaderService(file);
              repLoaderService.stateProperty().addListener(new ChangeListener<State>() {

                  /**
                   * {@inheritDoc}
                   */
                  @Override
                  public void changed(ObservableValue<? extends State> observable, State oldValue, State newValue) {
                      if (newValue == State.SUCCEEDED) {
                          // Setup display.
                          Rep plotRep = repLoaderService.getValue();
                          PlotRepPane plotRepPane = new PlotRepPane(plotRep);
                          root.setCenter(plotRepPane);
                      }
                  }
              });
              repLoaderService.start();
          }


      This exception only happens when the main Stage is closed before the FileChooser dialog is validated.

      There is no exception when the FileChooser is validated while the main Stage is still opened.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                lnerad Ľubomír Nerád
                Reporter:
                fbouyajfx Fabrice Bouyé (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported: