Rob Spoor wrote:Welcome to the Ranch!
JTree has method scrollPathToVisible(TreePath). This will not only scroll to that TreePath, but also expand all of its ancestors to make sure it's shown. Now all you need to do is create the right TreePath. If you use DefaultMutableTreeNode that's easy - just create a new TreePath around the value returned by the node's getPath() method. Otherwise you will have to construct it differently.
Once it's visible, you can call setSelectionPath(TreePath) to also select the node.
Rob Spoor wrote:I think that just makes sure that the node is made visible. I doubt that it matters whether that's on the top or bottom.
One trick could be to collapse and expand the node using collapsePath and expandPath. That should display as many of the children as possible.
Patrick Becker wrote:Interestingly enough, when I manually collapse and then expand the directory via the UI, it behaves as I would expect it to - the expanded node is placed at the top of the viewport, with the directory contents displayed below it.