Java JComponent to Image ensureImageLoaded(Component owner, Image image)

Here you can find the source of ensureImageLoaded(Component owner, Image image)

Description

ensure Image Loaded

License

Open Source License

Declaration

public static void ensureImageLoaded(Component owner, Image image) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.awt.Component;

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

import java.awt.image.ImageObserver;

public class Main {
    public static void ensureImageLoaded(Component owner, Image image) {
        if (image != null) {
            boolean done = false;
            Toolkit tk = owner.getToolkit();
            if (tk != null) {
                int flags = tk.checkImage(image, -1, -1, owner);
                if ((flags & (ImageObserver.ABORT | ImageObserver.ALLBITS | ImageObserver.ERROR
                        | ImageObserver.FRAMEBITS)) != 0) {
                    done = true;//from  w w w.j a  va 2s  .  c om
                }
            }
            if (!done) {
                MediaTracker mt = new MediaTracker(owner);
                mt.addImage(image, 0);
                try {
                    mt.waitForID(0);
                } catch (InterruptedException ex) {
                }
            }
        }
    }
}

Related

  1. buildImage(Component c)
  2. componentToImage(Component c)
  3. componentToImage(Component c)
  4. componentToImage(Component component, int resolution)
  5. doScreenshotToFile(final Component container, final Path filePath, final String imageType)
  6. findConnectedComponents(int[][] image)
  7. generateImageFileFromComponent(Component component, String filename, String Type)
  8. setCustomCursor(Component component, Image cursorImg, String name)
  9. setImage(Image im, Component c)