Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here is <a href="https://gist.github.com/1887631" rel="noreferrer">link to a solution</a> I created earlier for modal dialogs in JavaFX 2.1 The solution creates a modal stage on top of the current stage and takes action on the dialog results via event handlers for the dialog controls.</p> <p><em>Update</em></p> <p>The prior linked solution uses a dated event handler approach to take action after a dialog was dismissed. That approach was valid for pre-JavaFX 2.2 implementations. For JavaFX 8+ there is no need for event handers, instead, use the new Stage <a href="https://docs.oracle.com/javase/8/javafx/api/javafx/stage/Stage.html#showAndWait--" rel="noreferrer"><code>showAndWait()</code></a> method. For example:</p> <pre><code>Stage dialog = new Stage(); // populate dialog with controls. ... dialog.initOwner(parentStage); dialog.initModality(Modality.APPLICATION_MODAL); dialog.showAndWait(); // process result of dialog operation. ... </code></pre> <p>Note that, in order for things to work as expected, it is important to initialize the owner of the Stage <em>and</em> to initialize the modality of the Stage to either <a href="https://docs.oracle.com/javase/8/javafx/api/javafx/stage/Modality.html#WINDOW_MODAL" rel="noreferrer">WINDOW_MODAL</a> or <a href="https://docs.oracle.com/javase/8/javafx/api/javafx/stage/Modality.html#APPLICATION_MODAL" rel="noreferrer">APPLICATION_MODAL</a>.</p> <p>There are some high quality standard UI dialogs in <a href="http://code.makery.ch/blog/javafx-dialogs-official/" rel="noreferrer">JavaFX 8</a> and <a href="http://fxexperience.com/controlsfx/" rel="noreferrer">ControlsFX</a>, if they fit your requirements, I advise using those rather than developing your own. Those in-built JavaFX <a href="https://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/Dialog.html" rel="noreferrer">Dialog</a> and <a href="https://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/Alert.html" rel="noreferrer">Alert</a> classes also have <a href="https://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/Dialog.html#initOwner-javafx.stage.Window-" rel="noreferrer"><code>initOwner</code></a> and <a href="https://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/Dialog.html#initModality-javafx.stage.Modality-" rel="noreferrer"><code>initModality</code></a> and <a href="https://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/Dialog.html#showAndWait--" rel="noreferrer"><code>showAndWait</code></a> methods, so that you can set the modality for them as you wish (note that, by default, the in-built dialogs are application modal).</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload