本文介绍了是否可以通过Java 9获得JavaFX窗口的HWND?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Java 9将限制对私有API的任何访问.这意味着使用反射来检索窗口hwnd的已知方法将不再起作用.

Java 9 will restrict any access to private API. That means that the known methods of retrieving the window hwnd using Reflection won't work anymore.

还有没有办法得到他们?我问是因为我有一个提供用于操作任务栏的API的库(以与 Java9 提供). Java 9 API仍适用于AWT,因此希望我可以为Java 9和JavaFX设置项目.

Is there still a way to get them? I ask because I have a library that offers an API for manipulating the Taskbar (in a similar way that Java9 offers). The Java 9 API is still for AWT, so I hope I can get my project setup for Java 9 and JavaFX.

我曾经只调用私有方法,但这将停止工作.任何解决方案表示赞赏.如果可以使用JNA或BridJ进行本地调用,则可以.

I used to just call the private methods, but this will stop working.Any solution is appreciated. Native calls are ok if they can be done using JNA or BridJ.

推荐答案

一种方法可能是更改已经建议的解决方案如何我可以在JavaFX上获得JavaFX舞台的窗口句柄(hWnd)吗?在JDK9之前有用:-

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;
}

module-info.java有点像:

module your.module {
    requires javafx.graphics;
}

但是,由于javax.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

注释/提示: 来自 JEP-261:模块系统 -

这篇关于是否可以通过Java 9获得JavaFX窗口的HWND?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 05:18