code: protected boolean activateAndFocusWindow(Stage window) {
          if (!window.isFocused()) {
              if (!window.isShowing()) {
                  LOGGER.trace("cannot activate and focus the window '" + window.getTitle() + "' cause its window is not showing");
                  return false;
              }
              LOGGER.trace("try to activate and focus the window  '" + window.getTitle() + "' cause its window is not focused");
              StageFocusedListener stageFocusedListener = new StageFocusedListener(window);
              window.focusedProperty().addListener(stageFocusedListener);
  
              PlatformImpl.runAndWait(() -> {
                  window.toFront();
                  window.requestFocus();
              });
  
              boolean windowFocused = stageFocusedListener.waitUntilWindowFocused();
              window.focusedProperty().removeListener(stageFocusedListener);
              LOGGER.trace("window focused ? " + windowFocused);
              if (!window.isFocused()) {
                  LOGGER.warn("The window activation/focus process failed!!!");
                  return false;
              }
              LOGGER.trace("The window activation/focus process is completed!!!");
          } else {
              LOGGER.trace("the window '" + window.getTitle() + "' is already focused");
          }
          return true;
      }
docs: Try to activate and focus the stage window.
  
  @param window the stage window to activate.
  @return <code>true</code> only if the stage window is active at the end of the activation process.