Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Sending MouseEvents to JComponents visible through the bounds of another JComponent



You don't have to pass mouse events to your components manually. AWT does
this for you.

When you have non-rectangular components, you have to make sure, that your
JComponents return false for isOpaque(), and you have to override method
contains(x, y).

AWT uses the contains(x, y) method to determine if it should send the event
to the component. If the method returns false for a given coordinate, AWT
forwards the event to the component in lower z order.

I have found the following article very useful:
http://www.rz.fhtw-berlin.de/javakurs/magelang/awt/sec05-oneone.html

It's about AWT Components, but one can convert the example easily into Swing
JComponents.


-Werner



David Daniel wrote:
> [...]
> I have a JFrame containing JComponents that implement their own drawing
> via Graphics2D.draw(Shape). The JComponents are draggable, and most of
> their shapes do not fill their bounds. Hence, there are situations
> where:
>
> - two JComponents, A and B, both have Shapes drawn that are, say
> triangles,
> - A and B overlap with A above B (i.e., A's position index is lower),
> and
> - part of B's triangle shows through the bounds of A.
>
> In this situation, I need B to receive a mouse event when the part of B
> that is clicked on is visible through the bounds of A - normally, only
> A would receive a mouseEvent since the click is inside its bounds.
> It's easy enough to test that A's triangle is not under the mouse click
> with A.Shape.contains(Point). But I have not found a direct way to
> pass the mouseEvent to B.
> [...]
_______________________________________________
java-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/java-dev
Be sure to read the FAQ http://developer.apple.com/java/faq/ before posting
Do not post admin requests to the list. They will be ignored.

References: 
 >Sending MouseEvents to JComponents visible through the bounds of another JComponent (From: David Daniel <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.