Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bubbling up in the AWT event model?

If I implement an action event on a JFrame that has some buttons it give me the button clicked via getSource but if I implement on the same frame a mouse event it doesn't rise me the event for the buttons but only for that JFrame.

Why?

The event bubbling seems to work only for action event so what model Swing implements?

Which listeners types works in a bubbling way?

like image 508
xdevel2000 Avatar asked Dec 20 '25 17:12

xdevel2000


1 Answers

Event bubbling up in AWT only works for mouse events, and then only if there are no mouse listeners on the child component.

This can be quite confusing if you have, say, a JComboBox which is typically implemented by the PL&F with a text field and a button component. You might want to look up "glass panes".

I suggest ignoring containment hierarchy as much as possible. Also create listeners that know their context and dot use getSource. And don't extend classes (such as JFrame, JPanel and Thread) unnecessarily.

like image 96
Tom Hawtin - tackline Avatar answered Dec 22 '25 07:12

Tom Hawtin - tackline



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!