This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to propogate an event?

 
Jane Griscti
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ... can anyone point me to an example or explain how an event can be passed up to it's container.
I'm using a JLayeredPane to hold some JPanels. The JPanels in turn contain a JEditPane and may contain other components.
The user needs to be able to click on any one panel and have it move to the front. Problem is, the JEditPane fills the panel and ends up receiving the mouseClick; I need it to be passed on to the InfoLayer which has a listener that manipulates the panels.
Thanks
[This message has been edited by Jane Griscti (edited December 05, 2001).]
 
Manfred Leonhardt
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jane,
I am not really sure if this will work for you, but I can tell you about it anyway. The following command will place an event into the system queue so that it can be sent to registered listeners:
Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent( ae );
where ae is any AWTEvent. In your case you might be able to create a new AWTEvent using information from the one that you have received and just changing the source field to get it to work right.
Regards,
Manfred.
 
Jane Griscti
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Manfred. I'll try it out.
 
Jane Griscti
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This turned out to be fairly simple. Just posting the code in case anyone else needs it down the line
<pre>
public void mouseClicked(MouseEvent e){

InfoPanel ancestor = (InfoPanel) SwingUtilities.getAncestorOfClass(
InfoPanel.class,
(Component) e.getSource() );

MouseEvent me = new MouseEvent( ancestor,
e.getID(),
e.getWhen(),
e.getModifiers(),
e.getX(),
e.getY(),
e.getClickCount(),
e.isPopupTrigger() );
ancestor.dispatchEvent( me );
}
</pre>
------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform
Co-author Mike Meyers' Java 2 Certification Passport
[This message has been edited by Jane Griscti (edited December 05, 2001).]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic