Treeview - Scroll to display the selected path

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’?

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

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…

6 Likes