--- old/modules/javafx.swing/src/main/java/javafx/embed/swing/SwingNode.java 2017-09-22 10:55:08.000000000 +0530 +++ new/modules/javafx.swing/src/main/java/javafx/embed/swing/SwingNode.java 2017-09-22 10:55:08.000000000 +0530 @@ -74,6 +74,7 @@ import com.sun.javafx.sg.prism.NGNode; import com.sun.javafx.stage.FocusUngrabEvent; import com.sun.javafx.stage.WindowHelper; +import com.sun.javafx.tk.TKStage; import com.sun.javafx.PlatformUtil; import com.sun.javafx.embed.swing.SwingNodeHelper; import com.sun.javafx.scene.NodeHelper; @@ -199,6 +200,19 @@ javafx.scene.text.Font.getFamilies(); } + private void notifyNativeHandle(Window window) { + long rawHandle = 0L; + if (window != null) { + TKStage tkStage = WindowHelper.getPeer(window); + if (tkStage != null) { + rawHandle = tkStage.getRawHandle(); + } + } + if (lwFrame != null) { + jlfOverrideNativeWindowHandle.invoke(lwFrame, rawHandle); + } + } + /** * Attaches a {@code JComponent} instance to display in this {@code SwingNode}. *

@@ -278,6 +292,7 @@ * Must be called on EDT only. */ private static OptionalMethod jlfNotifyDisplayChanged; + private static OptionalMethod jlfOverrideNativeWindowHandle; static { jlfNotifyDisplayChanged = new OptionalMethod<>(JLightweightFrame.class, @@ -286,6 +301,9 @@ jlfNotifyDisplayChanged = new OptionalMethod<>( JLightweightFrame.class,"notifyDisplayChanged", Integer.TYPE); } + + jlfOverrideNativeWindowHandle = new OptionalMethod<>(JLightweightFrame.class, + "overrideNativeWindowHandle", Long.TYPE); } /* @@ -327,6 +345,10 @@ lwFrame.setContent(new SwingNodeContent(content)); lwFrame.setVisible(true); + if (getScene() != null) { + notifyNativeHandle(getScene().getWindow()); + } + SwingFXUtils.runOnFxThread(() -> { locateLwFrame(); // initialize location @@ -515,6 +537,9 @@ if (oldValue != null) { removeWindowListeners(oldValue); } + + notifyNativeHandle(newValue); + if (newValue != null) { addWindowListeners(newValue); } @@ -532,6 +557,7 @@ Window window = scene.getWindow(); if (window != null) { addWindowListeners(window); + notifyNativeHandle(window); } scene.windowProperty().addListener(sceneWindowListener); }