The Source for Java Technology Collaboration

Home » java.net Forums » Java Desktop Technologies » Swing & AWT

Thread: Pass events through the layers of a JLayeredPane

Welcome, Guest Help
Login Login
Guest Settings Guest Settings
This question is answered. Helpful answers available: 1. Correct answers available: 1.

Reply to this Thread Reply to this Thread Search Forum Search Forum Back to Thread List Back to Thread List

Permlink Replies: 5 - Last Post: Jul 24, 2008 11:02 PM by: lndeveloper
lndeveloper

Posts: 3
Pass events through the layers of a JLayeredPane
Posted: Jul 22, 2008 3:24 AM
 
  Click to reply to this thread Reply

I am using java/swing. Inside a JLayeredPane I have put various objects at various layers. As a result mouseclick events are caught only by the actionlisteners of the top level objects. I want to further "forward" these events to the underlying layer objects.

So the top-level objects handle the event first, and then "somehow" the event is forwarded to the next underlying level. If there is an object located at the underlying level at this position (and there is an actionlistener settled) the event is caught by this actionlistener and so on. I want all the process to be totally "transparent" for the objects at each layer, meaning that the object at each layer will not be able to distinguish if the event is fired from the user or being forwarded by an upper level.

Any ideas?

alexfromsun

Posts: 404
Re: Pass events through the layers of a JLayeredPane
Posted: Jul 22, 2008 5:52 AM   in response to: lndeveloper
Helpful
  Click to reply to this thread Reply

Hello lndeveloper

It is practically impossible to manually "forward" events which are caught by another component,
you'll have all kinds of problems if you continue this way

see A well-behaved GlassPane for more details

The JXLayer component may also be interesting for you

Thanks
alexp

lndeveloper

Posts: 3
Re: Pass events through the layers of a JLayeredPane
Posted: Jul 22, 2008 10:28 PM   in response to: alexfromsun
 
  Click to reply to this thread Reply

Although I didn't explore all the features of JXLayer, I understand that the main issue is to draw on top of other components, while they are still active. That's really cool, but I think it is not the solution to my problem.

It would be more helpful if I could make the overlay drawing catch some events, while the underlying componets catch some other events. Is it possible?

alexfromsun

Posts: 404
Re: Pass events through the layers of a JLayeredPane
Posted: Jul 23, 2008 4:48 AM   in response to: lndeveloper
 
  Click to reply to this thread Reply

Hello lndeveloper

It is possible with JXLayer - you make a custom LayerUI,
override e.g. processMouseEvents() method
and catch all mouse events there, for mouseEvents which you don't want to pass
to the underlying components you call event.consume(), that's it

Thanks
alexp

lndeveloper

Posts: 3
Re: Pass events through the layers of a JLayeredPane
Posted: Jul 24, 2008 11:02 PM   in response to: alexfromsun
 
  Click to reply to this thread Reply

Thank you alexfromsun!

sauvage

Posts: 65
Re: Pass events through the layers of a JLayeredPane
Posted: Jul 22, 2008 11:39 AM   in response to: lndeveloper
 
  Click to reply to this thread Reply

take a look at http://java.sun.com/javase/6/docs/api/java/awt/Container.html#setComponentZOrder(java.awt.Component,%20int)




 XML java.net RSS