The replacement code that you use with FXMLLoader , and not with the WebView created sample scene sample, is beautiful, you do not need to change it.
Your code will display the main scene for the main stage based on the fxml document (for my example, I used WebView as the main scene that you don't need, so you don't need any of the WebView related code from the bottom).
At the time you want to display the dialog, you need a trigger in your controller. As a simple example, you can configure fxml for your main scene, which includes only a button, and then provide an ActionHandler for the button in your controller (as in Introduction to the FXML Document ).
Now, instead of just doing println when the button is pressed as an introduction to FXML, call the dialog.show() method, as you did when loading the WebView document. What should happen is that now the dialog will be displayed on top of the scene you created fxml.
You will notice that the dialogue itself contains a scene. If you want (and this is optional), you can define the contents of the scene using fxml. To do this, during the construction of the dialog, you set up a new fxml and a new controller for the contents of the dialog box and load the created fxml scene for the dialog in the dialog mode. The code for this is pretty much identical to the code you used to load the main fxml scene into primaryStage.
Try the above and see if it works for you. If you're still stuck, I can probably create a specific gxml example from the lines of this answer.
Also note that the link was written some time ago, and now there is the showAndWait method in JavaFX, which facilitates code blocking when making a dialog call, and then allows you to process the result of the dialog without using some of the event handler mechanisms from the gist example. Strategies with and without showAndWait are perfectly acceptable solutions.