This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Java Event Bubbling? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Java Event Bubbling?" Watch "Java Event Bubbling?" New topic

Java Event Bubbling?

Tetsuo Suzuki

Joined: Feb 21, 2002
Posts: 22
If I have an event handler for an object that sits inside a container with it's own event handler, does the event "bubble up" to the outer container? This is the behavior of objects within DHTML so I was just wondering if this was the case with Java.
Thanks -
Rob Ross

Joined: Jan 07, 2002
Posts: 2205
Generally, GUI events only get sent to the object that currently has the focus, in the case of Keyboard events, or a single component that was the target of a mouse event. If you have a JPanel with a button on it and you click the button, only the button will actually get notified of the button click. The JPanel will not.
This has caused me problems in the past as sometimes you want both to get the event, and yet there is no easy way to propogate events - you can rethrow them, but it's problematic because you have to do a lot of calulations yourself about what objects could be in the "target zone" at the time of the event.

SCJP 1.4
I agree. Here's the link:
subject: Java Event Bubbling?
It's not a secret anymore!