I am not sure how you add this image to the JPanel, but I am supposing that you just paint this image on top of this panel. One way I think you can try is to set the preferred size and minimum size dynamically according to the image size you loaded, then call revalidate, and that should force the JScrollPane to scroll.
code sample:
public Dimension getMinimumSize()
{
return new Dimension(image.getWidth(panel), image.getHeight(panel));
}
in your load function, then call revalidate().
Hope this helps.
Originally posted by Skantha Kandiah:
Hi,
I am trying to create an application that can display different images in a single frame. The main frame contains a JScrollPane that contains a JPanel. Initally there is no image on the JPanel and there are no scrollbars on the scroll pane. When I add a large image to the JPanel the scrollbars don't appear on the scroll pane. What function do I need to call for the scroll bars to appear? I tried revalidate() and it did not work.
Thanks,
SK