public void setWidth(int width) { int height = 50; editorPane.setSize(width, 2000); try { height = (int) editorPane.modelToView(editorPane.getDocument().getLength() - 1).getY() + 25; } catch (BadLocationException e) { } editorPane.setSize(width, height); sp.setSize(width + 1, height + 1); sp.revalidate(); editorPane.revalidate(); cp.repaint(); }