JScrollPane () { TreeUtil.expandAll(myTree); JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(myTree); scrollPane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); if (myTree.getSelectionCount() == 0) { myTree.setSelectionRow(0); } if (myTree.getRowCount() >= 20) { scrollPane.getViewport().setPreferredSize(new Dimension(myTree.getPreferredScrollableViewportSize().width, 300)); } else { scrollPane.getViewport().setPreferredSize(myTree.getPreferredSize()); } if (myBuilder.isAutoselectOnMouseMove()) { myTree.addMouseMotionListener(new MouseMotionAdapter() { boolean myIsEngaged = false; @Override public void mouseMoved(MouseEvent e) { if (myIsEngaged) { final Point p = e.getPoint(); int index = myTree.getRowForLocation(p.x, p.y); myTree.setSelectionRow(index); } else { myIsEngaged = true; } } }); } return scrollPane; }