JDK-8222450 : Always on top Stage disappears after restoration from iconified
  • Type: Bug
  • Component: javafx
  • Sub-Component: window-toolkit
  • Affected Version: 8u181
  • Priority: P3
  • Status: Open
  • Resolution: Unresolved
  • OS: os_x
  • CPU: x86
  • Submitted: 2019-04-12
  • Updated: 2024-10-30
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbdUnresolved
Related Reports
Relates :  
Description
A DESCRIPTION OF THE PROBLEM :
If a stage is set with "Always on Top" property true & have MAC's dock setting "minimize window in application icon" enabled, then the stage disappears after its iconified and deiconified.

While debugging I added event listener to stage, & after the stage disappeared I moved the mouse where the window was before disappearing & can see mouse events been shown, hence it seems like the stage is there but not visible for some reason.

Then I tried Jframe, & same issue exists in Jframe too. Stumbled upon a already existing bug report for this, but that was closed as they thought its MAC version issue, but its NOT it happens on most MAC versions if the dock configuration is enabled as mentioned above.
https://bugs.java.com/bugdatabase/view_bug.do?bug_id=8192788

People can fix this kind of issues themselves if you can give event listener for all three buttons of window i.e close, minimize & maximize AND listener for dock icon click event. Also if we can define priority of listener, which should run first and which should run later can give good control over application. 
Example : here I could have removed Always on top before minimize begins

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Set Always on Top property true for your stage.
2. Enable Dock setting "minimize window in application icon"
3. Run application.
4. Minimize/Iconify your application.
5. Click on your app icon in dock to launch your app.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Window should appear.
ACTUAL -
Window appears for a split second and then disappears forever.

---------- BEGIN SOURCE ----------

package javafxbugreport;

import javafx.application.Application;
import javafx.application.Platform;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.event.ActionEvent;
import javafx.event.Event;
import javafx.event.EventDispatchChain;
import javafx.event.EventDispatcher;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

public class JavaFXBugReport extends Application {
    
    static Stage primaryStage;
    
    @Override
    public void start(Stage primaryStage) {
        this.primaryStage=primaryStage;
        
        Button btn = new Button();
        btn.setText("Say 'Hello World'");
        btn.setOnAction(new EventHandler<ActionEvent>() {
            
            @Override
            public void handle(ActionEvent event) {
                System.out.println("Hello World!");
            }
        });
        
        StackPane root = new StackPane();
        root.getChildren().add(btn);
        
        Scene scene = new Scene(root, 300, 250);
        
        primaryStage.setAlwaysOnTop(true);
        
        //Added event listener for debugging
        primaryStage.setEventDispatcher(new EventDispatcher() {
            
            final EventDispatcher originalEventDispatcher = primaryStage.getEventDispatcher();
            
            @Override
            public Event dispatchEvent(Event event, EventDispatchChain tail) {
                
                System.out.println("Event : " + event);
                
                return originalEventDispatcher.dispatchEvent(event, tail);
            }
        });
        
        primaryStage.setTitle("Hello World!");
        primaryStage.setScene(scene);
        primaryStage.show();
        
    }

    public static void main(String[] args) {
        launch(args);
    }
    
}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
//Workaround fix for disappearing window in MAC OS, if the "minimize window in application icon" is enabled.
        primaryStage.iconifiedProperty().addListener(new ChangeListener<Boolean>(){
            @Override
            public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
                
                if(oldValue.equals(newValue)){
                    if(!newValue){
                        Platform.runLater(new Runnable() {
                            @Override
                            public void run() {
                                primaryStage.hide();
                                primaryStage.show();
                            }
                        });
                    }
                }
            }
        });

FREQUENCY : always



Comments
I am able to reproduce this on jdk8-231. Will test on FX 13 soon.
17-07-2019

[~pbansal] Please check whether this also happens with FX 13.
15-04-2019