Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaFX Make object visible but not consume (ignore) clicks

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!

like image 926
SuperMrBlob Avatar asked Jun 11 '14 13:06

SuperMrBlob


1 Answers

All Nodes 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.

like image 166
awksp Avatar answered Nov 10 '22 07:11

awksp