我们正在 Windows 中构建 JavaFX 应用程序。
我已经尝试使用 JNA Native.getComponentPointer()
方法,它与 java.awt.panel
一起工作,但我想不出一个好的方法来使用 javafx.scene.layout.Pane
有谁知道有什么方法可以获取 Pane 的 hWnd 吗?
最佳答案
不幸的是,我认为这在 JavaFX 中是不可能的。我能看到的唯一具有原生对等体的是舞台。您可以使用 UI 分析器工具(例如 WinSpy)或 Windows SDK 中的“inspect.exe”或“visualuiaverifynative.exe”自行验证。
来自 Mixing Heavyweight and Lightweight Components by Oracle :
There are two kinds of graphics components in the Java programming language: heavyweight and lightweight. A heavyweight component is associated with its own native screen resource (commonly known as a peer). Components from the java.awt package, such as Button and Label, are heavyweight components.
[...]
A lightweight component has no native screen resource of its own, so it is "lighter." A lightweight component relies on the screen resource from an ancestor in the containment hierarchy, possibly the underlying Frame object. Components from the javax.swing package, such as JButton and JLabel, are lightweight components.
在这种情况下,JavaFX 就像 Swing;一个轻量级工具包,其中各种 ui 组件都是用 Java 编写的,没有本地对等组件。
关于java - 如何在 javafx8 中获取节点句柄,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47900118/