int (int width) { Dimension size = editorPane.getSize(); int editorPaneInsets = leftBorder + rightBorder + getSideComponentWidth(); editorPane.setSize(width - editorPaneInsets, Math.max(1, size.height)); int height; try { height = getPreferredSize().height; if (width - editorPaneInsets < editorPane.getMinimumSize().width) { JScrollBar scrollBar = pane.getHorizontalScrollBar(); if (scrollBar != null) height += scrollBar.getPreferredSize().height; } } finally { editorPane.setSize(size); } return height; }