Swing: Delegate events to child components of transformed parent

有些话、适合烂在心里 提交于 2019-12-02 04:41:28

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/16623276/swing-delegate-events-to-child-components-of-transformed-parent

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!