# Treeview - Scroll to display the selected path

**URL:** <https://forum.inductiveautomation.com/t/treeview-scroll-to-display-the-selected-path/17837>\
**Category:** Ignition\
**Created:** [April 26, 2018, 6:10am UTC](https://forum.inductiveautomation.com/t/treeview-scroll-to-display-the-selected-path/17837 "2018-04-26T06:10:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![zxcslo](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zxcslo/32/61610_2.png) [@zxcslo](https://forum.inductiveautomation.com/u/zxcslo)\
**Post date:** [April 26, 2018, 6:10am UTC](https://forum.inductiveautomation.com/t/treeview-scroll-to-display-the-selected-path/17837/1 "2018-04-26T06:10:25Z")

</div>

I have a Treeview component with many items.  
If I (programmatically) add the new item, I would like to auto scroll to the last added item/path.  
Now, when user add a new item, this item/path becomes selected, but user must scroll down or up by ‘hand’ to see the selected item.  
The same applies to the removing of items. If for example I remove the last item (from 100) in the treeview and the first one becomes selected, I must scroll to the top of the treeview to see the first item selected.

How can this be done ‘automatically’?

---

<div class="post-metadata">

**Author:** ![zxcslo](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zxcslo/32/61610_2.png) [@zxcslo](https://forum.inductiveautomation.com/u/zxcslo)\
**Post date:** [April 26, 2018, 8:03am UTC](https://forum.inductiveautomation.com/t/treeview-scroll-to-display-the-selected-path/17837/2 "2018-04-26T08:03:17Z")

</div>

I found it. 🕶  
You need to add this to treeView propertyChange event:

```auto
if event.propertyName == "folder":
	JTree = event.source.getViewport().getView()
	JTree.scrollPathToVisible(JTree.getSelectionPath())

```

EDIT: just to point out that propertyName “folder” is a my custom property…
