Listeners Blocking Each Other And Needing Events To Trickle Down
- From: bcr07548@xxxxxxxxxxxxx
- Date: 27 Jun 2006 17:35:56 -0700
I am having two problems with processing events. I know this is a
little long but please bear with me. I have a feeling that the
solution to one might have something to do with the other. Hopefully
someone can help out:
I am writing a program with a JPanel inside of another JPanel. In the
outter JPanel, a MouseMotionListener constantly updates a couple
variables with the mouse's current position within the window. When
only that listener is used, the event is triggered no matter where the
mouse is located within the panel (even if it is within the nested
panel.) However, when a MouseListener is added to the inner JPanel,
the outter JPanel's MouseMotionListener is no longer triggered when the
mouse is inside the inner JPanel. Basically, the event is stopping at
the top-most component and I would like it to "trickle" down. Is there
any way to "re-throw" the event from inside the inner JPanel's
MouseListener so that the outter JPanel's MouseMovementListener will be
still be triggered? I tried dispatching the event to the parent using
....getParent().dispatchEvent(e); inside each of the inner JPanel's
listener methods but it didn't seem to do anything.
The second problem that I am having is with the MouseListener for the
inner JPanel. When the user presses on the JPanel, mousePressed() is
triggered and a thread is created to do some work in the background
until mouseReleased() tells that thread to stop. The new thread relies
on data that needs to be updated by the outter JPanel's
MouseMovementListener but none of the outter panel's listener events
are triggered between the inner panel's mousePressed() and
mouseReleased() events. My initial thought was that maybe there was an
event queue inside of Java and the outter panel's events couldn't run
until after the inner panel's mousePressed() had finished but since
mousePressed() starts a thread and returns, I wouldn't think that would
be the problem. Are other events not allowed to occur between "pairs"
of events like mousePressed() and mouseReleased()?
So, those are my problems - needing events to "trickle down" to parent
components and needing the outter panel's event handle to run in
between the inner panel's mousePressed() and mouseReleased() events. I
hope someone can help. I would post the code but it's a little messy
at the moment and hopefully these problems aren't THAT unusual (the
first one especially since other systems let you do it.) Any help
someone could offer would be great.
-Brandon R
.
- Prev by Date: Re: Best Layout?
- Next by Date: Re: font size in pixels?
- Previous by thread: font size in pixels?
- Next by thread: an enclosing instance that contains javax.swing.text.StyleContext.NamedStyle is required
- Index(es):
Relevant Pages
|