void () { JTree tree = getTree(); AbstractLayoutCache cache = treeState; if (tree != null && isValid(tree) && cache != null && tree.isLargeModel() && is("ide.tree.experimental.preferred.width")) { Rectangle paintBounds = tree.getVisibleRect(); if (!paintBounds.isEmpty()) { JScrollPane pane = UIUtil.getParentOfType(JScrollPane.class, tree); if (pane != null) { JScrollBar bar = pane.getHorizontalScrollBar(); if (bar != null && bar.isOpaque() && bar.isVisible()) { paintBounds.height += bar.getPreferredSize().height; } } Insets insets = tree.getInsets(); TreePath path = cache.getPathClosestTo(0, paintBounds.y - insets.top); int row = cache.getRowForPath(path); if (row >= 0) { Rectangle buffer = new Rectangle(); int maxPaintX = paintBounds.x + paintBounds.width; int maxPaintY = paintBounds.y + paintBounds.height; int width = 0; for (; path != null; path = cache.getPathForRow(++row)) { Rectangle bounds = cache.getBounds(path, buffer); if (bounds == null) { LOG.warn("The bounds for the row " + row + " of the tree " + tree + " with model " + treeModel + " are null, looks like a bug in " + cache); continue; } width = Math.max(width, bounds.x + bounds.width); if ((bounds.y + bounds.height) >= maxPaintY) break; } width += insets.left + insets.right; if (width < maxPaintX) { if (!is("ide.tree.prefer.to.shrink.width.on.scroll")) { width = maxPaintX; } else if (paintBounds.width < width || !is("ide.tree.prefer.aggressive.scrolling.to.the.left")) { int margin = intValue("ide.tree.preferable.right.margin", 25); if (margin > 0) { width = Math.min(width + paintBounds.width * margin / 100, maxPaintX); } } } preferredSize.width = width; preferredSize.height = insets.top + insets.bottom + cache.getPreferredHeight(); validCachedPreferredSize = true; return; } } } super.updateCachedPreferredSize(); }