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.
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!
All Node
s in JavaFX have a setMouseTransparent()
method, as detailed here, where the mouseTransparent
property is:
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With