简体   繁体   English

如何在javafx8中获取节点句柄

[英]How to get Node handle in javafx8

We're building a JavaFX application in Windows. 我们正在Windows中构建JavaFX应用程序。

I've tried to use JNA Native.getComponentPointer() method which works with java.awt.panel , but I can't figure out a good way to do this with a javafx.scene.layout.Pane 我曾尝试使用JNA Native.getComponentPointer()方法,该方法适用于java.awt.panel ,但我无法找到一个使用javafx.scene.layout.Pane执行此操作的好方法

Does anyone know of any way to do get hWnd for a Pane ? 有没有人知道有什么方法可以获得一个Pane的hWnd?

Unfortunately, I do not think that this is possible with JavaFX. 不幸的是,我不认为JavaFX可以实现这一点。 The only thing that I can see that has a native peer is the Stage. 我能看到的唯一具有本地同伴的是舞台。 You can verify this yourself by using a ui analyzer tool, such as WinSpy, or "inspect.exe" or "visualuiaverifynative.exe" from the Windows SDK. 您可以使用ui分析工具(如WinSpy)或Windows SDK中的“inspect.exe”或“visualuiaverifynative.exe”自行验证。

From Mixing Heavyweight and Lightweight Components by Oracle : Oracle混合重量级和轻量级组件

There are two kinds of graphics components in the Java programming language: heavyweight and lightweight. Java编程语言中有两种图形组件:重量级和轻量级。 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. java.awt包中的组件(如Button和Label)是重量级组件。

[...] [...]

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. 轻量级组件依赖于包含层次结构中的祖先的屏幕资源,可能是底层的Frame对象。 Components from the javax.swing package, such as JButton and JLabel, are lightweight components. javax.swing包中的组件(如JButton和JLabel)是轻量级组件。

In this case, JavaFX is just like Swing; 在这种情况下,JavaFX就像Swing; a lightweight toolkit where the various ui components are all written in Java and do not have a native peer. 一个轻量级工具包,其中各种ui组件都是用Java编写的,没有本地对等体。

As far as my reading of the doc goes, there is a 1:1 relationship between an hWnd and a window object. 就我对文档的阅读而言, hWnd与窗口对象之间存在1:1的关系。 Panes and Nodes aren't Windows , so trying to get an hwnd specific node doesn't seem to make a lot of sense. 窗格和节点不是Windows ,因此尝试获取一个特定节点的节点似乎没有多大意义。

The most you could ask for is the hwnd of the window containing the node. 您可以要求的最多是包含节点的窗口的hwnd。 See: 看到:

Applying the function from the answer to the linked question gets: 将答案中的函数应用于链接的问题得到:

Pointer hwnd = getWindowPointer(node.getScene().getWindow());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM