Skip to main content

Mouse Events on Nodeobjects which are behind other Nodeobjects

2 replies [Last post]
Joined: 2008-03-27

I wonder if this is sensible?
Small example:

<br />
package CheckFunctionsBehindObjects;</p>
<p>import javafx.application.Frame;<br />
import javafx.application.Stage;<br />
import javafx.scene.geometry.Rectangle;<br />
import javafx.scene.paint.Color;<br />
import javafx.scene.geometry.Circle;<br />
import javafx.input.*;<br />
import javafx.scene.*;<br />
import java.lang.System;</p>
<p>Frame {<br />
    title: "MyApplication"<br />
    width: 200<br />
    height: 200<br />
    closeAction: function() {<br />
        java.lang.System.exit( 0 );<br />
    }<br />
    visible: true</p>
<p>    stage: Stage {<br />
        content: [<br />
            Rectangle {<br />
                x: 10, y: 10<br />
                width: 140, height: 90<br />
                fill: Color.YELLOWGREEN<br />
                cursor: Cursor.HAND<br />
                onMouseClicked: function( e: MouseEvent ):Void {<br />
                    System.out.println("rect clicked")<br />
                }<br />
            },<br />
            Circle {<br />
                centerX: 100, centerY: 100<br />
                radius: 40<br />
                fill: Color.BLACK<br />
                cursor: Cursor.MOVE<br />
                onMouseClicked: function( e: MouseEvent ):Void {<br />
                    System.out.println("circle clicked")<br />
                }<br />
            }<br />
<p>    }<br />
}<br />

There are two Shapes. The rect is behind the circle. Both Shapes have an onMouseClicked MouseEvent which call the function println(). When i click on the overlapping area both functions are called. Does this make sense? For example if there is a Button with an onclick Glow effect in Front of an area and the area has an onclick effect too but should not run with the click on the can i realize this?
Furthermore i have to give my Circle a Cursor, else there will be the Cursor of the rect in the overlapping area.

In my opinion only the nodeobject in the front should define click actions on Stage. What do you think?


Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2008-05-26

I disagree. I use multiple mouse events quite often. I have one window-filling transparent rectangle over my whole application that allows me to handle certain things (certain drag operations, unselects when clicking into nothing, etc.) more efficiently.

If you want a node object to call the mouse exclusively, set its [i]blocksmouse[/i] attribute to true and you have it.

Joined: 2008-03-27

thx, did not know about the blocksmouse attribute