Skip to main content

How to capture mouse events in a parent JPanel?

1 reply [Last post]
jacek
Offline
Joined: 2003-08-22
Points: 0

I'm sure this must be Swing 101, but I can't seem to find the equivalent of the standard Windows capture() function that redirects all mouse events to a particular control until it decides to release it.

basically, I don't want the mouseEntered or mouseExited events of the child controls to be triggered, I want the parent JPanel to always be notified when the mouse enters into it or one of its child controls.

Thanks in advance,
Jacek

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
mgrev
Offline
Joined: 2003-08-12
Points: 0

Add a MouseListener to all sub components in the JPanel. You can use the same MouseListener for them all.

An easy way is overriding .add(Component) in JPanel (and possibly other add methods) to do this automatically whenever a Component is added to the panel.

Regards,
Mikael