I'm trying to receive MouseEvents for an invisible node in JavaFX 2.2. Think of it as an interactive but invisible Zone that should trigger an action for example when the mouse hovers it. The problem is, that this is not a statically defined zone, but there are multiple zones (a lot of it) that can be moved and resized by the application. So for my use-case it would be a lot of overhead to globally listen to mouse-movement and perform a manual detection of - say - MouseMove-Events.
Currently, I'm experimenting with a transparent Rectangle (new Rectangle(200, 100, Color.TRANSPARENT)
), but the actual / final Application will use some sort of a Pane for it, because it's actually a draggable container for other components (when not full of components, it has transparent areas and MouseMoves must be detected on these transparent areas as well).
I additionally would appreciate answers that help me to get a better understanding of how JavaFX 2.2 generally handles MouseEvents depending on the visibility of nodes.
My experiments have shown the following general insights so far:
Given a transparent Scene: Mouse Events will only be passed to foreign Applications (visually below the Scene) when the user clicks on a transparent area. There's no way to pass a mouse-event "to the OS" when the user clicks on a visible pixel of the Scene. Right?
A Pane on top of other nodes will per default swallow any MouseEvent unless it is MouseTransparent or the MouseClick appears on a non-visible (transparent) area.
pickOnBounds(true|false)
is there to enable (true
) bounds-based (rectangular) detection of MouseEvents or disable it (false
). Latter effectively handles mouse-events only for visible pixels / areas.pickOnBounds(true)
seems not to work for completely invisible nodes. Right?My experiments have shown, that a node needs at least a fill of -
new Color(1,1,1,0.004)
to be considered visible. Lower alpha-values are considered invisible, which causes MouseEvents not to be handled, even ifpickOnBounds(true)
has been called.
Did I get this right? Then there would be no way for an invisible Node to receive MouseEvents.
Or is there a special requirement for pickOnBounds
to work? Do I need to call it only after the node has been shown or something similar?
Any other suggestions?