Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java Event Bubbling?

 
Tetsuo Suzuki
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 -
Tetsuo!
 
Rob Ross
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic