import javafx.application.*;
import javafx.scene.*;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.stage.*;

public class JavaFXBugIconified extends Application {
    @Override
    public void start(Stage primaryStage) throws Exception {

        VBox pin = new VBox();
        Button button = new Button("iconified");

        pin.setPrefWidth( 600);
        pin.getChildren().add(button);
        pin.getChildren().add(new ToggleButton());

        primaryStage.setResizable(false);
        primaryStage.setScene(new Scene(pin));

        primaryStage.iconifiedProperty().addListener((obs, o, n) -> {
            System.err.println("iconified: " + n);
        });

        primaryStage.show();

        // Not important for the bug, but useful for testing
        button.onActionProperty().set((e) -> {
            primaryStage.setResizable(true);
            primaryStage.setIconified(true);
            new Thread(() -> {
                try {
                    Thread.sleep(500);
                    System.err.println("ASDF");
                    Thread.sleep(2000);
                    Platform.runLater(() -> {
                        primaryStage.setIconified(false);
                        primaryStage.setResizable(false);
                    });
                } catch (Throwable ee) {
                    ee.printStackTrace();
                }
            }).start();
        });
    }
}
