Re: consuming mouse events

From: Dave Thorn (davet_at_fysh.org)
Date: 06/24/04


Date: 24 Jun 2004 09:20:42 GMT

In article <GOxCc.105$df.26@newsfe2-gui.server.ntli.net>, VisionSet wrote:
>
>
> "Dave Thorn" <davet@fysh.org> wrote in message
> news:slrncdl37r.m0v.davet@bowl.fysh.org...
>>
>> Imagine I have a panel that contains lots of components. I want these
>> components to handle certain mouse events (e.g. right-clicks) but not
>> other (left-clicks). In a component's mousePressed(e) I can check if
>> I'm interested in the event, but how do I then decide I don't want
>> anything to do with it, and let the panel handle it?
>
> Ask the parent to handle it:
>
> Component.getParent()

Do I manually call the mousePressed(e) method?

public void mousePressed(MouseEvent e) {
        if (notInteresed())
                component.getParent().mousePressed(e);
}

There are two problems with that.

The first is that the coordinates of the mouseEvent are relative to
the component, not the parent.

The second is that, in my scenario, the parent registers a
mouseMotionListener in the press. However, if the original press was
on a component, the parent doesn't get the mouseDrag events
(MOUSE_DRAGGED events are delivered to the Component in which the
mouse button was pressed until the mouse button is released
(regardless of whether the mouse position is within the bounds of the
Component).)

-- 
dave thorn

Quantcast