This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I have BufferedImage [canvas object]. Its size is 300x300. I can zoom it using mouse wheel and the method:
Unfortunately, the image can enlarge too much. The scroll bars should appear. I do not know how to do it.
I use JPanel for showing the image and I wrap that JPanel with JScrollPane, but it doesn't work.
Most here will be able to help you better if you create a small compilable program that compiles, runs and demonstrates your problem. That way we can experience the problem first hand, modify the code and help you find a solution quickly. This is called creating an SSCCE, and for more on this, please read the link: SSCCE
Key to this process is to create a whole new class for this that extracts all the pertinent constructs from your current classes, but has no extraneous code that is unrelated to your problem.
Til you create and post one, as a SWAG, while you seem to be trying to resize the component holding the image, I wonder if you're calling revalidate on the component holding it (I believe here it would be the JScrollPane's JViewport) so that Swing knows to relayout the newly sized component in its container.
Joined: Feb 23, 2007
For instance, here is my take on a possible SSCCE for your problem. Run the program first, and the un-comment the line with the //!! comment to see what effect call to revalidate has: