How do I make sure an Image is loaded before I try to display it?

John Zukowski

You can use the AWT MediaTracker to start and wait for the loading of an Image object.

Image image = ...;
MediaTracker tracker = new MediaTracker(component or this);
tracker.addImage(image, 0);
try {
} catch (InterruptedException e) {
  System.out.println("Interrupted while loading Image");

At this point, if everything went okay, the image would be loaded. You can check the status with statusAll() or statusID() to see if they loaded successfully.