Java ImageIcon Load getImageIcon(String name)

Here you can find the source of getImageIcon(String name)

Description

Charge une image

License

Open Source License

Declaration

public static ImageIcon getImageIcon(String name) 

Method Source Code

//package com.java2s;
/*//from   w w w. j av  a 2  s. c om
 * 05/16/2003 - 10:29:03
 * 
 * GUIUtilities.java - Copyright (C) 2003 Dreux Loic dreuxl@free.fr
 * Modifications : 
 * janvier 2009 : B. DABO 
 * Message d'erreur en fran?ais si exception lors de la cr?ation de la font 
 * 
 * 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 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.
 */

import java.awt.Toolkit;

import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import javax.swing.ImageIcon;

public class Main {
    private static Map<String, ImageIcon> hashtable = new HashMap<String, ImageIcon>();

    /**
     * Charge une image
     */
    public static ImageIcon getImageIcon(String name) {
        Toolkit toolkit = Toolkit.getDefaultToolkit();

        URL url;

        /*if (hashtable.containsKey(name) == true)
        return (ImageIcon) hashtable.get(name);
            
        ImageIcon icon = new ImageIcon(toolkit.getImage(AnalyseFrame.class.getResource("images/" + name)));
            
        hashtable.put(name, icon);
            
        return icon;
        */

        url = ClassLoader.getSystemResource("org/analyse/core/gui/images/" + name);
        if (url == null) {
            url = ClassLoader.getSystemResource("org/analyse/core/gui/images/home.png");
        }

        ImageIcon icon = new ImageIcon(url);

        hashtable.put(name, icon);

        return icon;
    }
}

Related

  1. getImageIcon(final String location)
  2. getImageIcon(Image imp, int width, int height)
  3. getImageIcon(String filename)
  4. getImageIcon(String filename, String description)
  5. getImageIcon(String name)
  6. getImageIcon(String path)
  7. getImageIcon(String path, String description)
  8. getImageIcon(String res)
  9. getImageIcon(String resource)