JavaFX 2.2在坐标处获取节点(可视树命中测试) [英] JavaFX 2.2 get node at coordinates (visual tree hit testing)

查看:144
本文介绍了JavaFX 2.2在坐标处获取节点(可视树命中测试)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在鼠标/任意坐标下获取控件列表(或第一个)?我知道WPF有VisualTreeHelper.HitTest,它有一个回调函数,可用于过滤掉一点上的所有控件。 JavaFX有类似的东西吗? (或者不同,我只关心给定点的第一个元素)我已经看到很多信息来获取节点的坐标,但没有关于如何通过坐标获取节点的信息。

How can I get a list of (or the first one of) the controls under the mouse/arbitrary coordinates? I know WPF has VisualTreeHelper.HitTest and it has a callback that can be used to filter out all the controls at a point. Is there something similar for JavaFX? (or different, I just care for the first element at a given point) I've seen lots of information to get coordinates of a node, but no information on how to get a node by coordinates.

推荐答案

您可以使用 node.impl_pickNode(x,y)

来自 impl_pickNode 方法的文档(复制自 source )。

Documentation from the impl_pickNode method (copied from the source).

/** 
 * Finds a top-most child node that contains the given coordinates.
 *
 * Returns the picked node, null if no such node was found.
 *
 * @deprecated This is an internal API that is not intended for use 
 *             and will be removed in the next version. 
 **/
public final Node impl_pickNode(double parentX, double parentY)

请注意评论中的弃用警告,使用风险自负。

Note carefully the deprecation warning in the comment and use at your own risk.

更新

JavaFX问题跟踪器中存在现有功能请求:外汇应提供父母.pick()例程。此功能请求适用于公众拣货API,将来不会弃用。请求的功能描述为:例程可以返回单个节点或由z坐标排序的鼠标
下面的所有节点的列表。该功能尚未安排实施,直到Van Ness发布,即最初JDK8发布后的发布(即该功能最早要到2013年圣诞节才可用)。

There is an existing feature request in the JavaFX issue tracker: FX should provide a Parent.pick() routine. This feature request is for a public picking API which will not be deprecated in the future. The requested feature is described as: "The routine could return a single Node or a list of all the Nodes below the mouse ordered by z coordinates". The feature is not scheduled for implementation until the "Van Ness" release which is the release after the initial JDK8 release (i.e. the feature won't be available until Christmas 2013 at the earliest).

这篇关于JavaFX 2.2在坐标处获取节点(可视树命中测试)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆