views:

64

answers:

1

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?

+2  A: 

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.

Tom Hawtin - tackline
but the click on the button is an ActionEvent...
xdevel2000
@xdevel2000 `JFrame` does not have `addActionListener`.
Tom Hawtin - tackline