I have a JFrame in which I need to have a TIFF image displayed and scaled. When a component gains focus I need to zoom in on a specific area of that image. For lack of a better method I simply created two PlanarImages, one scaled the appropriate size for the zoom out and one scaled to the size I would need when zoomed in and then converted those to BufferedImage. I use the BufferedImage in an ImageIcon which is in turn used in a JLabel which is in turn used in a JFrame. When I need to zoom in I get a Subimage of the BufferedImage that has the appropriate scaling and set that as ImageIcon's image. It works... except for one thing... when I do the zoom in the image doesn't appear, well it will appear as soon as I change the size of the frame at all with my mouse. I'm not sure what I'm doing wrong, my code is getting called in the Event Handling thread and should be thread safe, I don't know why it doesn't wait for it to load. I tried using a MediaTracker and waitForAll on the image but that doesn't help.
Call validate() or invalidate() on the component that is drawing the image... if the images are different sizes the layout manager may need to lay out the component again. validate() and invalidate() force the layout manager to run again.
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Tried that. Actually I tried revalidate() but now I tried validate() and invalidate() and it doesn't seem to help. I changed the alignment of the icon to the top left because I discovered that it was getting painted it was just getting painted in part of the frame that isn't showing on the screen apparently. Even so, most of the image shows up but the far right 50 or so pixels are gray for some unknown reason. Even as I change the image when each field gains focus that blank area is still there. The thing is, as soon as I touch the resize with my mouse it works, and will work perfectly the rest of the time the application is running. Hell, even if I resize the big zoomed out picture in the first place and then go through the fields which makes it change to the zoomed in versions it works perfectly. I don't get it.
Another thing to add, I tried removing the alignment to the top left in the initialization and the image doesn't show up again. However, I added in code to the above just before the invalidate that changes the label's size to the appropriate size (as it seemed to me that the label wasn't getting its size updated before the layout and paint occurred) and it works, except I STILL have that 50-100 pixels of blank space until I resize it at some point, even if it's before the point at which I zoomed in on the images! Oh... and that's using a size of 500x100 and everyone of my images that use that width/height have the problem, however the smaller ones that are 300x100 display perfectly. [ August 05, 2003: Message edited by: Ken Blair ]
I've noticed that the 'blank' part is the area of the frame that wasn't viewable before the resize. What I mean is that initially the frame ends up at 460x600 due to the scaling, when I resize it goes to 500x100. Those 40 pixels on the right are the 'blank' area. Also, when I go back to 460x600 from the 500x100 (when I zoom out) everything below the 100 pixels is 'blank' as well. To be honest I don't really understand your code. Two months ago I'd never programmed before so I'm kind of new and I don't really know much about imaging. What am I doing wrong? Also, is there a need/reason to go through all the hassle of what you did to generate the images? [ August 06, 2003: Message edited by: Ken Blair ]
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop