JDK-8181476 : [macos] Stages with StageStyle.UTILITY are always on-top when initialized without an owner
  • Type: Bug
  • Component: javafx
  • Sub-Component: window-toolkit
  • Affected Version: 8,9
  • Priority: P2
  • Status: Resolved
  • Resolution: Fixed
  • OS: os_x
  • CPU: x86
  • Submitted: 2017-06-01
  • Updated: 2020-06-01
  • Resolved: 2017-10-06
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.
JDK 10 JDK 8
10Fixed 8u261Fixed
Description
FULL PRODUCT VERSION :
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
15.6.0 Darwin Kernel Version 15.6.0: Fri Feb 17 10:21:18 PST 2017; root:xnu-3248.60.11.4.1~1/RELEASE_X86_64 x86_64

A DESCRIPTION OF THE PROBLEM :
If you create a stage with StageStyle.UTILITY, it is always on-top if it doesn't have an owner. Not only is it on-top of other javafx stages but also all other applications.

This may be intended but is entirely undocumented that the style will change how the window operates. Documentation makes it seem the stage style is cosmetic only.


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
package sample;

import javafx.application.Application;
import javafx.stage.Modality;
import javafx.stage.Stage;
import javafx.stage.StageStyle;

public class Main extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception{
        primaryStage.setTitle("Hello World");
        primaryStage.show();

        Stage dummyStage = new Stage();
        dummyStage.initModality(Modality.NONE);
        // by setting this to utility the stage will now always be on-top of other applications
        // may not intended but it is not documented to do that
        dummyStage.initStyle(StageStyle.UTILITY);
        dummyStage.setAlwaysOnTop(false);
        dummyStage.show();

        dummyStage.requestFocus();
    }


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

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

CUSTOMER SUBMITTED WORKAROUND :
Create a dummy stage that is transparent with width/height 0/0 and set it as the owner of the window.


Comments
http://hg.openjdk.java.net/openjfx/10-dev/rt/rev/2a24fe2e8740
06-10-2017

Looks good. +1
05-10-2017

http://cr.openjdk.java.net/~azvegint/jdk/10/8181476/00/ "Utility windows are always in the same layer: the top layer. They are visible only when their application is active." [0] However utility windows stays topmost if not owned by another window, as a solution we can utility window level to normal. Also there is a reproducible crash, if run this sample with debug build: 2017-06-06 13:28:35.030 java[25102:1958778] *** Assertion failure in -[GlassWindow_Panel _validateCollectionBehavior:], /Library/Caches/com.apple.xbs/Sources/AppKit/AppKit-1504.83.101/AppKit.subproj/NSWindow.m:14741 2017-06-06 13:28:35.032 java[25102:1958778] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'utility panels cannot be fullscreen primary' *** First throw call stack: ( 0 CoreFoundation 0x00007fff8372d2cb __exceptionPreprocess + 171 1 libobjc.A.dylib 0x00007fff9853848d objc_exception_throw + 48 2 CoreFoundation 0x00007fff83732042 +[NSException raise:format:arguments:] + 98 3 Foundation 0x00007fff8517ac80 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 195 4 AppKit 0x00007fff811e1dd7 -[NSWindow _validateCollectionBehavior:] + 298 5 AppKit 0x00007fff811e2099 -[NSWindow setCollectionBehavior:] + 33 6 libglass.dylib 0x000000012681281a _createWindowCommon + 1066 7 ??? 0x000000010dad4db5 0x0 + 4524428725 ) libc++abi.dylib: terminating with uncaught exception of type NSException Abort trap: 6 It is addressed with this fix also. [0] https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/WinPanel/Concepts/ChangingMainKeyWindow.html
06-06-2017

Issue reproducible only in MacOS, not in windows and Linux. Failed in both JDK 8 and 9. macOS Sierra 10.12.3 ------------------- 8u60 : Fail 8u121 : Fail 8u131 : Fail 9ea+167 : Fail 9ea+172 : Fail -------------------
02-06-2017