One way could be to make changes to an already suggested solution to How can I get the window handle (hWnd) for a Stage in JavaFX? useful prior to JDK9 as :-
try {
TKStage tkStage = stage.impl_getPeer();
Method getPlatformWindow = tkStage.getClass().getDeclaredMethod("getPlatformWindow" );
getPlatformWindow.setAccessible(true);
Object platformWindow = getPlatformWindow.invoke(tkStage);
Method getNativeHandle = platformWindow.getClass().getMethod( "getNativeHandle" );
getNativeHandle.setAccessible(true);
Object nativeHandle = getNativeHandle.invoke(platformWindow);
return new Pointer((Long) nativeHandle);
} catch (Throwable e) {
System.err.println("Error getting Window Pointer");
return null;
}
with a module-info.java
somewhat like :
module your.module {
requires javafx.graphics;
}
But since javax.graphics
exports the package internally to specific modules as:
exports com.sun.javafx.tk to
javafx.controls,
javafx.deploy,
javafx.media,
javafx.swing,
javafx.web;
You can try adding a compiler option to still make use of it as
--add-exports javax.graphics/com.sun.javafx.tk=your.module
Note/Imp : Disclaimer from JEP-261:Module System -
The --add-exports
and --add-opens
options must be used with great
care. You can use them to gain access to an internal API of a library
module, or even of the JDK itself, but you do so at your own risk: If
that internal API is changed or removed then your library or
application will fail.