Java Image setImage(Image im, JComponent c)

Here you can find the source of setImage(Image im, JComponent c)

Description

Ensures that Images is completely loaded

License

Open Source License

Declaration

public static boolean setImage(Image im, JComponent c) 

Method Source Code

//package com.java2s;
/**//w w w.ja v a  2s  .co m
 * MegaMek - Copyright (C) 2000-2002 Ben Mazur (bmazur@sev.org)
 * 
 *  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.
 */

import java.awt.Image;
import java.awt.MediaTracker;
import javax.swing.JComponent;

public class Main {
    /**
     * Ensures that Images is completely loaded
     */
    public static boolean setImage(Image im, JComponent c) {
        boolean b = true;
        MediaTracker mt = new MediaTracker(c);
        mt.addImage(im, 0);
        try {
            mt.waitForID(0);
        } catch (InterruptedException e) {
            System.out.println("Error while image loading."); //$NON-NLS-1$
            b = false;
        }
        if (mt.isErrorID(0)) {
            System.out.println("Could Not load Image."); //$NON-NLS-1$
            b = false;
        }
        return b;
    }
}

Related

  1. renderComponentToImage(JComponent component)
  2. save(Image image, File file, String formatName)
  3. saveComponentAsImage(final String path, final Component target, final String format)
  4. SaveImageToFile(Image img, String filename, String outformat)
  5. scaleBarcodeMaxWidth(Image i, int width, int cropHeigth)
  6. setImageDimension(Image imagen)
  7. showImage(final String title, final Image image)
  8. showImage(Image image)
  9. showImage(Image image, String title)