griFlo griFlo - 1 year ago 93
Java Question

Javafx Dialog (Alert) not visible if owner is minimized

Why is a Dialog (Alert) in javafx not correctly shown if the owner is minimized.

look at the following Code:

public class JavaFxSample2 extends Application {

public void start(Stage primaryStage) throws InterruptedException, ExecutionException {
primaryStage.setTitle("open alert in 2 seconds");
Pane pane = new Pane();
Button b = new Button("open dialog");
b.setOnMouseClicked(event -> {
Task<Void> task = new Task<Void>() {
protected Void call() throws Exception {
return null;
task.stateProperty().addListener((observable, oldValue, newValue) -> {
if (newValue == State.SUCCEEDED) {
Alert alert = new Alert(AlertType.INFORMATION, "Hello");
Thread thread = new Thread(task);


Scene scene = new Scene(pane, 300, 275);

public static void main(String[] args) {

If you minimize the application within the 2 seconds, and then maximize it again (after the 2 seconds) you dont see the dialog but it is there somehow (the stage is locked till you press esc or enter)

if you dont minimize the stage the dialog is shown correctly.

is this a bug? am i doing it wrong?

System is Windows 7, Java

Ok. it seems like its really a bug:

Answer Source

Found a (possible) solution. But is this really a good solution?

before showing the Alert I execute the following line:

((Stage) alert.getOwner()).setIconified(false);

If someone has a better idea i'll delete my answer.