# ListBox and mouse wheel issue

**URL:** <https://forum.juce.com/t/listbox-and-mouse-wheel-issue/6535>\
**Category:** General JUCE discussion\
**Created:** [March 8, 2011, 9:37am UTC](https://forum.juce.com/t/listbox-and-mouse-wheel-issue/6535 "2011-03-08T09:37:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![alexsmode](https://avatars.discourse-cdn.com/v4/letter/a/c68b51/32.png) [@alexsmode](https://forum.juce.com/u/alexsmode)\
**Post date:** [March 8, 2011, 9:37am UTC](https://forum.juce.com/t/listbox-and-mouse-wheel-issue/6535/1 "2011-03-08T09:37:48Z")

</div>

If ListBox::viewport scrollbars are not displayed, mouseWheelMove events are not forwarded to parent.

To fix this issue, I have change this code:

`void ListBox::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
{
    getHorizontalScrollBar()->mouseWheelMove (e, wheelIncrementX, 0);
    getVerticalScrollBar()->mouseWheelMove (e, 0, wheelIncrementY);
}`

To this one:

`void ListBox::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
{
    ScrollBar* hScroolBar = viewport->getHorizontalScrollBar();
    ScrollBar* vScroolBar = viewport->getVerticalScrollBar();
    if (hScroolBar->isVisible() || vScroolBar->isVisible())
    {
      hScroolBar->mouseWheelMove (e, wheelIncrementX, 0);
      vScroolBar->mouseWheelMove (e, 0, wheelIncrementY);
    }
    else // if no viewport scrollbars, forward mouseWheel event to parent.
      return Component::mouseWheelMove (e, wheelIncrementX, wheelIncrementY);
}`

This fix can be useful when Viewport children contain ListBox components.  
I hope my first post can help.

---

<div class="post-metadata">

**Author:** ![haydxn](https://avatars.discourse-cdn.com/v4/letter/h/5fc32e/32.png) [@haydxn](https://forum.juce.com/u/haydxn)\
**Post date:** [March 8, 2011, 9:51am UTC](https://forum.juce.com/t/listbox-and-mouse-wheel-issue/6535/2 "2011-03-08T09:51:51Z")

</div>

on a related note, i’ve found the following bug related to mousewheel after resizing a listbox.

1. Have a listbox with visible scrollbars (i.e. at least one-too-many items to fit)
2. Resize the listbox so that all items now fit (and the scrollbars disappear)
3. Move the mousewheel, and notice that a vertical scrollbar has now appeared with inappropriate bounds

You can reproduce it with the jucedemo, on the TableComponents page - although it’d probably be tricky to make the window big enough if you’re running at a low resolution 🙂

---

<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:** [March 8, 2011, 10:32am UTC](https://forum.juce.com/t/listbox-and-mouse-wheel-issue/6535/3 "2011-03-08T10:32:58Z")

</div>

Thanks chaps, I’ll take a look at those issues right away!
