JScrollPane Scrolling Problem
Posted on 2006-10-22
I have a very frustrating problem that i have been working on for several hours with no success. I basically want a panel on which i draw an image (using graphics.drawimage). I want to be able to zoom into the image (by making the panel bigger and drawing a bigger image on it), and when the image panel gets bigger than the window, scroll bars appear.
I have got this partially working, however when the panel is larger than the window and i try increasing the size even more, the scrollbars do not adjust to the new size. And also, when i reduce the size from very large (but still bigger than the window) the scroll bars do not change.
Im sorry if i havent explained myself very well!
Here's some sample code:
JPanel imagePane = new JPanel;
imagePane.parent = this;
previewScroller = new JScrollPane(imagePane);
When i try to resize the image i do this:
INSIDE THE JPANEL [imagePane]:
this.setPreferredSize(new Dimension(newWidth(), newHeight()));
repaint(); // calls a overridden paint method that draws an image onto the panel
parent.previewScroller.revalidate(); // SHOULD sort out the scrollbars!
I'm really not sure why its not working! I hope someone can shed some light on this. If you need any more information just let me know.