tags:

views:

13

answers:

1

I am having an issue where I try and load some images using the ToolKit class, this is done like this:

  Toolkit tk = Toolkit.getDefaultToolkit();

  Image image = tk.createImage(imageFile.getPath());

but when I try to later draw these images onto my canvas (located inside JFrames) oftentimes it only draws some of the images on the canvas but it raises no exceptions. After a lot of investigation I am fairly convinced that the images are not done being loaded by the time they are being drawn but I am having trouble verifying this. I read in the documentation that there is a class called an ImageOberserver and if you check its property called the Allbit this will tell you if the object is fully loaded but I have found no good example of how to do this or any good documentation describing this process.

Also, I have found that the toolkit that is returned when running this on my mac is apple.awt.CToolKit but I can find no documentation on this class either. Does anyone know if the CtoolKit creates a new thread when you run the method createImage? Does anyone know where I could find the docs for this class?

+2  A: 

Images load incrementally, and may be animated. Typically you can just use javax.swing.ImageIcon. java.awt.MediaTracker is the traditional route to make sure an image has completed loading.

Tom Hawtin - tackline