JavaFX使对象可见但不消耗(忽略)单击 [英] JavaFX Make object visible but not consume (ignore) clicks

查看:203
本文介绍了JavaFX使对象可见但不消耗(忽略)单击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

标题说明了一切:我在JavaFX中有一个矩形(用于透明度/不透明度效果)但我希望人们能够点击它。

Title says it all: I have a rectangle in JavaFX (for transparency/opacity effects) yet I want people to be able to 'click through' it.

因此,当我说点击时,我的意思是当你点击它时,Java应该假装它不存在,而是点击该对象下面的任何东西。当你使用setVisible(false)创建一些不可见的东西时,这正是发生的事情 - 你设置的任何对象都不会消耗你的鼠标生成的点击事件。然而,对象变得不可见 - 这是我不想要的。

So when I say click through, I mean when you click it, Java should pretend it isn't there and instead 'click' on whatever is beneath that object. When you make something invisible with setVisible(false), this is exactly what happens - whatever object you set invisible doesn't consume the click events that your mouse generates. However, the object becomes invisible - something I do not want.

有可能吗?谢谢你提供任何帮助!

Is it possible? Thankyou for any help you can provide!

推荐答案

所有节点 s in JavaFX有一个 setMouseTransparent()方法,详见 here ,其中 mouseTransparent 属性为:

All Nodes in JavaFX have a setMouseTransparent() method, as detailed here, where the mouseTransparent property is:


如果为true,则此节点(及其所有子节点)对鼠标事件完全透明。选择鼠标事件的目标时,将mouseTransparent设置为true的节点及其子树将不予考虑。

If true, this node (together with all its children) is completely transparent to mouse events. When choosing target for mouse event, nodes with mouseTransparent set to true and their subtrees won't be taken into account.

如果需要更复杂的鼠标透明效果,例如只有父节点是透明的,你可能需要将它与其他一些处理点击检测的方法结合起来(它的名字现在让我逃脱我认为它是 pickOnBounds ;关于如何使用它,我不能肯定地说。我认为通过将我的应用程序中的所有内容设置为,我更加滥用它是 false ,但我不记得哪一个,很遗憾无法告诉你需要哪些节点设置该属性为),但对于应该有效的简单鼠标透明度。

If you need more complex mouse transparency effects, such as having only the parent node be transparent, you may need to combine that with some other method dealing with click detection (its name escapes me at the moment I think it was pickOnBounds; as for how to use it, I can't say for sure. I think I more abused it by setting literally everything in my app to either true or false, but I don't remember which one, and unfortunately wouldn't be able to tell you what nodes you'd need to set that property for), but for simple mouse transparency that should work.

这篇关于JavaFX使对象可见但不消耗(忽略)单击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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