Dynamically Changing the Size of a JScrollPane’s Client

In short: setSize(..) doesn’t work at all, you’ll need setPreferredSize(..) followed by revalidate()

if (changed) {
    //Update client's preferred size because
    //the area taken up by the graphics has
    //gotten larger or smaller (if cleared).
    drawingArea.setPreferredSize(/* the new size */);

    //Let the scroll pane know to update itself
    //and its scroll bars.
    drawingArea.revalidate();
}

Resources:
http://java.sun.com/docs/books/tutorial/uiswing/components/scrollpane.html#update

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.