ImageIcon does not guarantee load?

i have a jlabel with an ImageIcon. seems as though imageicon uses mediatracker to track load progress and is supposed to return only when image is loaded.

however, when i use ii.getImageLoadStatus() i get MediaTracker.ABORTED. yet the image is displayed

QUESTION: how can i force to make ImageIcon (within JLAbel) to display onscreen before proceeding further into code. i tried to use imageicon.tracker.waitForAll() yet it has protected access, so i cannot use it. once again, i want jlabel with imageicon to actually display before proceeding, yet it seems as though imageicon returns BEFORE load is over and i cannot access ImageIcon's mediatracker.

any ideas?

nikita

[716 byte] By [dukehoops] at [2007-9-26 2:34:52]
# 1

Hi,

I've found the following on this thread http://groups.google.com/groups?hl=en&safe=off&th=52be2a5ff040a15c,3&seekm=36B72C73.E3CDDCB1%40globalserve.net#p :

/** Stops the current process until the image is loaded. */

public static void waitForImage(Component component, Image image) {

MediaTracker tracker = new MediaTracker(component);

try {

tracker.addImage(image, 0);

tracker.waitForID(0);

}

catch(InterruptedException e) { e.printStackTrace(); }

}

Usage:

iconimage = getImage(getCodeBase(), "image.jpg");

waitForImage(this, iconimage);

yourclass.setimage(iconimage);

Hope this helps.

leukbr at 2007-6-29 10:00:11 > top of Java-index,Archived Forums,Java Programming...