简体   繁体   中英

Swing: Delegate events to child components of transformed parent

I've got a custom component GameViewCanvas extends JPanel that will hold a number of tiles (800x800 textures). Now in GameViewCanvas I've overridden the paint() method, so that it will paint the children on a transformed canvas (zoom, panning and rotation).

I now want to delegate events like MouseEvent and MouseMotionEvent to the respective children - the problem of course being that Swing has no idea where the children are on the actual frame. I thought I might be able to just override a method like getComponentAt in the parent but no such luck - I figure Swing is looping through the children directly?

Maybe I'm going about this all wrong, so please advice. Thanks in advance.

Take a look at JXLayer . It does exactly what you've just asked.

There are some excellent examples by Piet Blok, which have, unfortunately, disappeared off the net. To this end, I've made them available here .

Take a look at the TestWrapped demo in the pbjar source. It is probably the (among) the best example.

在此处输入图片说明

ps - JXLayer is now officially part of Java 7, known as JLayer

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM