Here you can find the source of autoscroll(JTree tree, Point cursorLocation)
private static void autoscroll(JTree tree, Point cursorLocation)
//package com.java2s; /* Copyright (c) 2010, Carl Burch. License information is located in the * com.cburch.logisim.Main source code and at www.cburch.com/logisim/. */ import java.awt.Insets; import java.awt.Point; import java.awt.Rectangle; import javax.swing.JTree; public class Main { private static final Insets DEFAULT_INSETS = new Insets(20, 20, 20, 20); private static void autoscroll(JTree tree, Point cursorLocation) { Insets insets = DEFAULT_INSETS; Rectangle outer = tree.getVisibleRect(); Rectangle inner = new Rectangle(outer.x + insets.left, outer.y + insets.top, outer.width - (insets.left + insets.right), outer.height - (insets.top + insets.bottom)); if (!inner.contains(cursorLocation)) { Rectangle scrollRect = new Rectangle(cursorLocation.x - insets.left, cursorLocation.y - insets.top, insets.left + insets.right, insets.top + insets.bottom); tree.scrollRectToVisible(scrollRect); }/*from ww w . j a v a2s .co m*/ } }