# Child-component independent mouseEnter/mouseExit?

**URL:** <https://forum.juce.com/t/child-component-independent-mouseenter-mouseexit/12747>\
**Category:** General JUCE discussion\
**Created:** [April 24, 2014, 1:55pm UTC](https://forum.juce.com/t/child-component-independent-mouseenter-mouseexit/12747 "2014-04-24T13:55:30Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![chkn](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/chkn/32/3862_2.png) [@chkn](https://forum.juce.com/u/chkn)\
**Post date:** [April 24, 2014, 1:55pm UTC](https://forum.juce.com/t/child-component-independent-mouseenter-mouseexit/12747/1 "2014-04-24T13:55:30Z")

</div>

For a hovering-mechanism, i need to know if the mouse is currently over a component, even if this mouse is currently over a containing&nbsp;component (with also has interaction, so hitTest is no option).

Does anybody has an idea how to quickly solve that? (without modification of the child components)

---

<div class="post-metadata">

**Author:** ![chkn](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/chkn/32/3862_2.png) [@chkn](https://forum.juce.com/u/chkn)\
**Post date:** [April 25, 2014, 7:21am UTC](https://forum.juce.com/t/child-component-independent-mouseenter-mouseexit/12747/2 "2014-04-25T07:21:26Z")

</div>

bump

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [April 25, 2014, 9:56am UTC](https://forum.juce.com/t/child-component-independent-mouseenter-mouseexit/12747/3 "2014-04-25T09:56:32Z")

</div>

You can do this with a MouseListener.. They can be set to listen to all events in all subcomponents of the one you attach it to.

---

<div class="post-metadata">

**Author:** ![chkn](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/chkn/32/3862_2.png) [@chkn](https://forum.juce.com/u/chkn)\
**Post date:** [April 25, 2014, 11:05am UTC](https://forum.juce.com/t/child-component-independent-mouseenter-mouseexit/12747/4 "2014-04-25T11:05:58Z")

</div>

So i have to attach it on every sub component?

---

<div class="post-metadata">

**Author:** ![dave96](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/dave96/32/8487_2.png) [@dave96](https://forum.juce.com/u/dave96)\
**Post date:** [April 25, 2014, 11:18am UTC](https://forum.juce.com/t/child-component-independent-mouseenter-mouseexit/12747/5 "2014-04-25T11:18:09Z")

</div>

No, just pass true as the second parameter to addMouseListener, that will automatically recieve events from all nested components. Then just check the mouse position relative to the parent to see if the mouse is still inside or not.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [April 25, 2014, 11:18am UTC](https://forum.juce.com/t/child-component-independent-mouseenter-mouseexit/12747/6 "2014-04-25T11:18:14Z")

</div>

No - see Component::addMouseListener

---

<div class="post-metadata">

**Author:** ![chkn](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/chkn/32/3862_2.png) [@chkn](https://forum.juce.com/u/chkn)\
**Post date:** [April 25, 2014, 2:56pm UTC](https://forum.juce.com/t/child-component-independent-mouseenter-mouseexit/12747/7 "2014-04-25T14:56:02Z")

</div>

thanks :)&nbsp;

its just easier, mouseEnter/mouseExit will do the job
