Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java: define unit component for mouse events

I want to have a JPanel called mainPanel and add several components on it; Also I defined a mouseAdapter and added to my mainPanel that overrides mouseEntered and mouseExited to for example change background color of mainPanel when mouse entered it. But when mouse entered to mainPanel and entered to components I added on it (for example labels) mouseExited event is called; But I don't want this as mouse is in area of mainPanel; I want it be called just when mouse exited mainPanel area; and also want this for mouseEntered. I previously added mouseListeners to components on mainPanel but it is not a clear solution. Can anyone tell me a clear way for my purpose?

thanks your attention; Good lock

like image 254
sajad Avatar asked Nov 22 '25 13:11

sajad


1 Answers

Getting mouseEvents for a component and all its children is ... tricky to get right. You might consider to rely on stable (and extensively tested :-) code around. The jdk7 way of doing it is to use a JLayer (which internally registers an AWTEventListener as it has all priviledges). For earlier versions, you can use its predecessor JXLayer

like image 166
kleopatra Avatar answered Nov 25 '25 06:11

kleopatra



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!