JScrollPane (final JTree tree, final MultilineTreeCellRenderer renderer) { final TreeCellRenderer defaultRenderer = tree.getCellRenderer(); JScrollPane scrollpane = new JBScrollPane(tree){ private int myAddRemoveCounter = 0; private boolean myShouldResetCaches = false; @Override public void setSize(Dimension d) { boolean isChanged = getWidth() != d.width || myShouldResetCaches; super.setSize(d); if (isChanged) resetCaches(); } @Override public void reshape(int x, int y, int w, int h) { boolean isChanged = w != getWidth() || myShouldResetCaches; super.reshape(x, y, w, h); if (isChanged) resetCaches(); } private void resetCaches() { resetHeightCache(tree, defaultRenderer, renderer); myShouldResetCaches = false; } @Override public void addNotify() { super.addNotify(); if (myAddRemoveCounter == 0) myShouldResetCaches = true; myAddRemoveCounter++; } @Override public void removeNotify() { super.removeNotify(); myAddRemoveCounter--; } }; scrollpane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); scrollpane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); tree.setCellRenderer(renderer); scrollpane.addComponentListener(new ComponentAdapter() { @Override public void componentResized(ComponentEvent e) { resetHeightCache(tree, defaultRenderer, renderer); } @Override public void componentShown(ComponentEvent e) { // componentResized not called when adding to opened tool window. // Seems to be BUG#4765299, however I failed to create same code to reproduce it. // To reproduce it with IDEA: 1. remove this method, 2. Start any Ant task, 3. Keep message window open 4. start Ant task again. resetHeightCache(tree, defaultRenderer, renderer); } }); return scrollpane; }