title: What is the good use to create a wait / notify window with javafx?
body: <p>I want to create a popup only once and change the content via the for loop; (for each files dropped). I want to answer yes/no/noAll/yesAll. So I need a wait() just after to show the popup with the first movie content. And if I said "no" for example, I want notify() the thread to be unlock in the aim to reach until the second movie. In this case, The popup content changes with the second movie and I have again a wait() until I answer via the buttons etc.</p>
  
  <p>I tried a lot of things without successfull :/ and I get this error:</p>
  
  <pre><code>Exception in thread "JavaFX Application Thread" java.lang.IllegalMonitorStateException
      at java.lang.Object.notifyAll(Native Method)
      at controllers.HomeController.notifyPopup(HomeController.java:150)
      at controllers.HomeController.lambda$1(HomeController.java:208)
      at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
  </code></pre>
  
  <p>I meet a problem on <code>dialog.notify()</code>
  Maybe I don't apply the notify() on the same dialog object but it's the case, no ?</p>
  
  <p>Thank you in advance for your help </p>
  
  <p>This is my partial code : Search <code>// LOOK HERE</code> in the code to see the main lines</p>
  
  <pre><code>public class HomeController {
  
  
    @FXML
    private Label home;
  
    @FXMLViewFlowContext
    private ViewFlowContext context;
  
    RenameFiles film;
    SimpleBooleanProperty  noAllProperty = new SimpleBooleanProperty(false);
    SimpleBooleanProperty  yesAllProperty = new SimpleBooleanProperty(false);
    SimpleBooleanProperty  continuePopup = new SimpleBooleanProperty(false);
    ArrayList&lt;Path&gt; arrayFile = new ArrayList&lt;Path&gt;();
    Stage stage;
    Boolean firstFile = false;
    JFXDialogLayout content;
    JFXDialog dialog;
  
    @PostConstruct
    public void init() throws FlowException, VetoException {
      Settings settings = (Settings) context.getRegisteredObject("Settings");
      content = new JFXDialogLayout();
      dialog = new JFXDialog((StackPane) context.getRegisteredObject("ROOT"), content, JFXDialog.DialogTransition.CENTER);
  
      home.setOnDragOver(new EventHandler&lt;DragEvent&gt;() {
        @Override
        public void handle(DragEvent event) {
          Dragboard dragboard = event.getDragboard();
          if (dragboard.hasFiles()) {
            event.acceptTransferModes(TransferMode.ANY);
          } else {
            event.consume();
          }
        }
      });
  
      // Dropping over surface
      home.setOnDragDropped(new EventHandler&lt;DragEvent&gt;() {
        @Override
        public void handle(DragEvent event) {
          Dragboard dragboard = event.getDragboard();
          boolean success = false;
          if (dragboard.hasFiles()) {
            arrayFile = new ArrayList&lt;Path&gt;();
            success = true;
            noAllProperty.set(false);
            yesAllProperty.set(false);
            dragboard.getFiles().forEach(file -&gt; {
              if(Files.isDirectory(file.toPath())){
                try(Stream&lt;Path&gt; paths = Files.walk(Paths.get(file.toURI()))) {
                  paths.forEach(filePath -&gt; {
                    if (Files.isRegularFile(filePath)) 
                    arrayFile.add(filePath);
                  });
                } catch (IOException e) {
                  e.printStackTrace();
                } 
              }else if (Files.isRegularFile(file.toPath()))
              arrayFile.add(file.toPath());
  
            });
          }
          event.setDropCompleted(success);
          event.consume();
  
          arrayFile.forEach(file -&gt; {
            film = new RenameFiles(new File(file.toString()), settings);
            if(!noAllProperty.getValue()){
              if(film.getNameWithoutExt().length() &gt; 0){
                if(!yesAllProperty.getValue()){
                      try {
                          firstFile = true;
                          contentPopup();
  
                          if(firstFile) {
                            dialog.show();
                            dialog.setOverlayClose(false);
                            firstFile = false;
                          }
                   // LOOK HERE
                          waitPopup(dialog);
  
                      } catch (FlowException | InterruptedException e) {
                          // TODO Auto-generated catch block
                          e.printStackTrace();
                      }           
                }else{
                  film.applyRename(film.getCleanName());
                }
              }
            }
          });
        }
      });
    }
    public synchronized void waitPopup(JFXDialog dialog) {
          // This guard only loops once for each special event, which may not
          // be the event we're waiting for.
          while(!continuePopup.getValue()) {
              try {
                  dialog.wait();
              } catch (InterruptedException e) {}
          }
      }
  
    public synchronized void notifyPopup(JFXDialog dialog) {
          continuePopup.setValue(true);
          dialog.notifyAll();
      }
  
    private void contentPopup() throws FlowException, InterruptedException{
  
      JFXButton buttonYesPopupRename = new JFXButton("Yes");
      buttonYesPopupRename.setPrefHeight(30);
      buttonYesPopupRename.setPrefWidth(70);
      buttonYesPopupRename.setId("buttonYesPopupRename");
      buttonYesPopupRename.setButtonType(ButtonType.RAISED);
      buttonYesPopupRename.setOnAction(e -&gt; { film.applyRename(film.getCleanName());continuePopup.setValue(true);notifyPopup(dialog); });  // LOOK HERE
      buttonYesPopupRename.setStyle("-fx-text-fill:WHITE;-fx-background-color:#5264AE;-fx-font-size:14px;");
  
      JFXButton buttonNoPopupRename = new JFXButton("No");
      buttonNoPopupRename.setPrefHeight(30);
      buttonNoPopupRename.setPrefWidth(70);
      buttonNoPopupRename.setId("buttonNoPopupRename");
      buttonNoPopupRename.setButtonType(ButtonType.RAISED);
      buttonNoPopupRename.setOnAction(e -&gt; { continuePopup.setValue(true); notifyPopup(dialog); });  // LOOK HERE
      buttonNoPopupRename.setStyle("-fx-text-fill:WHITE;-fx-background-color:#5264AE;-fx-font-size:14px;");
  </code></pre>