Java Image Wait waitForImageData(Image image, Component comp)

Here you can find the source of waitForImageData(Image image, Component comp)

Description

Waits until all the data of an Image is present.

License

Open Source License

Parameter

Parameter Description
image a parameter
comp a parameter

Declaration

public static void waitForImageData(Image image, Component comp) 

Method Source Code


//package com.java2s;
/*/*from   w  w  w  .ja v a  2 s .c  o  m*/
 * TV-Browser
 * Copyright (C) 04-2003 Martin Oberhauser (martin_oat@yahoo.de)
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * CVS information:
 *  $RCSfile$
 *   $Source$
 *     $Date: 2010-06-28 19:33:48 +0200 (Mon, 28 Jun 2010) $
 *   $Author: bananeweizen $
 * $Revision: 6662 $
 */

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

import javax.swing.JLabel;

public class Main {
    /** The helper label. */
    private static final JLabel HELPER_LABEL = new JLabel();

    /**
     * Waits until all the data of an Image is present.
     * <p>
     * An Image is after construction only loaded when the data is used. The loading
     * occurs in an extra Thread and can take some time, so it might happen, that
     * an Image is not present after construction (it will be painted partly).
     * This method waits until the whole Image is loaded. The Component
     * <code>comp</code> is needed to monitor the preparing of the Image. You can
     * pass any Component (it will not be changed).
     * </p>
     * <p>You should not use this method when creating an ImageIcon. ImageIcons already use a MediaTracker internally.</p>
     *
     * @param image
     * @param comp
     */
    public static void waitForImageData(Image image, Component comp) {
        if (comp == null) {
            comp = HELPER_LABEL;
        }

        MediaTracker tracker = new MediaTracker(comp);
        tracker.addImage(image, 0);
        try {
            tracker.waitForID(0);
        } catch (Exception ex) {
        }
    }
}

Related

  1. waitForImage(Image image, Component c)
  2. waitForImage(Image image, Component component)
  3. waitForImage(Image image, Component component)
  4. waitForImage(java.awt.Image image)
  5. waitForImage(java.awt.Image image)
  6. waitImage(Image i)
  7. waitImage(Image image)
  8. wallPaper(Component comp, Graphics g, Image image)