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



There is a method in SwingUtilities(convertMouseEvent) to retarget the mouse event; if the wrong component gets it, it can look up the proper component, convert the event, and either re-post it to the event queue or invoke Component.dispatchEvent on it.




On Feb 5, 2004, at 1:38 PM, David Daniel wrote:

I apologize if this gets posted more than once, but the original post did not appear on the list's site after 15 hours, so I'm posting again.

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. The glassPane could be made visible, and then intercept and handle all mouseEvents, but this might complicate drags and DnD events. Or, an AWTEventListener could register with the Toolbox and handle mouseEvents. Both of these solutions seems a bit round-about.

Is there a more straight forward mechanism for passing the mouseEvent on to JComponent B in this scenario?

Thanks,
-David

David Daniel
New Mexico State University
email@hidden
_______________________________________________
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.
_______________________________________________
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.