void (@NotNull JTree tree, @NotNull Rectangle bounds, boolean centered) { JViewport viewport = ComponentUtil.getViewport(tree); if (viewport != null) { int width = viewport.getWidth(); if (!centered && tree instanceof Tree && !((Tree)tree).isHorizontalAutoScrollingEnabled()) { bounds.x = -tree.getX(); bounds.width = width; } else { int control = JBUIScale.scale(20); // calculate a control width bounds.x = Math.max(0, bounds.x - control); bounds.width = bounds.x > 0 ? Math.min(bounds.width + control, centered ? width : width / 2) : width; } int height = viewport.getHeight(); if (height > bounds.height && height < tree.getHeight()) { if (centered || height < bounds.height * 5) { bounds.y -= (height - bounds.height) / 2; bounds.height = height; } else { bounds.y -= bounds.height * 2; bounds.height *= 5; } if (bounds.y < 0) { bounds.height += bounds.y; bounds.y = 0; } int y = bounds.y + bounds.height - tree.getHeight(); if (y > 0) bounds.height -= y; } } tree.scrollRectToVisible(bounds); }