# Listbox Scroll To

**URL:** <https://forum.inductiveautomation.com/t/listbox-scroll-to/11936>\
**Category:** Ignition\
**Created:** [July 15, 2016, 4:27pm UTC](https://forum.inductiveautomation.com/t/listbox-scroll-to/11936 "2016-07-15T16:27:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kraenbring](https://avatars.discourse-cdn.com/v4/letter/k/f4b2a3/32.png) [@Kraenbring](https://forum.inductiveautomation.com/u/Kraenbring)\
**Post date:** [July 15, 2016, 4:27pm UTC](https://forum.inductiveautomation.com/t/listbox-scroll-to/11936/1 "2016-07-15T16:27:41Z")

</div>

Looking for the way to make a listbox scroll to what is selected. (It really should be doing this by default.)

If you are using your arrow keys within the lisbox, the scroll bars move to show what is selected. But if you use a button to set the selected Value or Index, it does not scroll up or down to show it. It selects the item, but if it’s off the viewable area, you don’t get to see it.

I’ve used some scrolling code for the power table before that works well:  
from java.awt import Rectangle  
table = event.source.parent.getComponent(‘MainTable’).getTable()  
viewport = table.getParent()  
rect = viewport.getViewRect()  
newRect = Rectangle(rect.x, rect.y + 288, rect.width, rect.height)  
table.scrollRectToVisible(newRect)

But I need to use a Listbox for this.

Thoughts?

---

<div class="post-metadata">

**Author:** ![jpark](https://avatars.discourse-cdn.com/v4/letter/j/a88e57/32.png) [@jpark](https://forum.inductiveautomation.com/u/jpark)\
**Post date:** [July 15, 2016, 5:57pm UTC](https://forum.inductiveautomation.com/t/listbox-scroll-to/11936/2 "2016-07-15T17:57:50Z")

</div>

`if event.propertyName == "selectedIndex":
	jl = event.source.getComponent(0).getComponent(0)
	jl.ensureIndexIsVisible(event.newValue)`

Put this in the propertyChange event of the listbox

---

<div class="post-metadata">

**Author:** ![Kraenbring](https://avatars.discourse-cdn.com/v4/letter/k/f4b2a3/32.png) [@Kraenbring](https://forum.inductiveautomation.com/u/Kraenbring)\
**Post date:** [July 15, 2016, 6:18pm UTC](https://forum.inductiveautomation.com/t/listbox-scroll-to/11936/3 "2016-07-15T18:18:55Z")

</div>

Worked like a champ! Exactly what I needed. Thanks!  
Where would I find those commands?
