Java Image Wait waitFor(Image image)

Here you can find the source of waitFor(Image image)

Description

Wait until the image has been loaded completely

License

Open Source License

Declaration

public static Image waitFor(Image image) 

Method Source Code

//package com.java2s;
/**// w  ww .j a va2 s .c  o m
 * RSS framework and reader
 * Copyright (C) 2004 Christian Robert
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

import java.awt.Component;

import java.awt.Image;
import java.awt.MediaTracker;

import javax.swing.JLabel;

public class Main {
    private static final Component DUMMY_COMP = new JLabel();

    /**
     * Wait until the image has been loaded completely
     */
    public static Image waitFor(Image image) {
        try {
            MediaTracker tracker = new MediaTracker(DUMMY_COMP);
            tracker.addImage(image, 0);
            tracker.waitForAll();
        } catch (InterruptedException e) {
            // Do nothing
        }
        return image;
    }
}

Related

  1. waitForImage(Image image)
  2. waitForImage(Image image)
  3. waitForImage(Image image)
  4. waitForImage(Image image, Component c)