< prev index next >
modules/javafx.swing/src/main/java/javafx/embed/swing/SwingNode.java
Print this page
*** 72,87 ****
--- 72,89 ----
import com.sun.javafx.scene.DirtyBits;
import com.sun.javafx.sg.prism.NGExternalNode;
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;
import sun.awt.UngrabEvent;
import sun.swing.JLightweightFrame;
import sun.swing.LightweightContent;
+ import sun.swing.SwingAccessor;
/**
* This class is used to embed a Swing content into a JavaFX application.
* The content to be displayed is specified with the {@link #setContent} method
* that accepts an instance of Swing {@code JComponent}. The hierarchy of components
*** 197,206 ****
--- 199,220 ----
//Workaround for RT-34170
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();
+ }
+ }
+ SwingAccessor.getJLightweightFrameAccessor()
+ .overrideNativeWindowHandle(lwFrame, rawHandle);
+ }
+
/**
* Attaches a {@code JComponent} instance to display in this {@code SwingNode}.
* <p>
* The method can be called either on the JavaFX Application thread or the Event Dispatch thread.
* Note however, that access to a Swing component must occur from the Event Dispatch thread
*** 325,334 ****
--- 339,352 ----
}
}
lwFrame.setContent(new SwingNodeContent(content));
lwFrame.setVisible(true);
+ if (getScene() != null) {
+ notifyNativeHandle(getScene().getWindow());
+ }
+
SwingFXUtils.runOnFxThread(() -> {
locateLwFrame(); // initialize location
if (focusedProperty().get()) {
activateLwFrame(true);
*** 513,522 ****
--- 531,543 ----
private final ChangeListener<Window> sceneWindowListener = (observable, oldValue, newValue) -> {
if (oldValue != null) {
removeWindowListeners(oldValue);
}
+
+ notifyNativeHandle(newValue);
+
if (newValue != null) {
addWindowListeners(newValue);
}
};
*** 530,539 ****
--- 551,561 ----
private void addSceneListeners(final Scene scene) {
Window window = scene.getWindow();
if (window != null) {
addWindowListeners(window);
+ notifyNativeHandle(window);
}
scene.windowProperty().addListener(sceneWindowListener);
}
private void addWindowListeners(final Window window) {
< prev index next >