Java ImageIcon Create createImageIcon(String path)

Here you can find the source of createImageIcon(String path)

Description

Create an ImageIcon from the image at the specified path

License

Open Source License

Parameter

Parameter Description
path The path of the image

Return

The image icon, or null if the image doesn't exist

Declaration

public static ImageIcon createImageIcon(String path) 

Method Source Code

//package com.java2s;
/**/* www  .  jav a2 s  .  c om*/
    
   BlackBoard BreadBoard Designer
   Written and maintained by Matthias Pueski 
       
   Copyright (c) 2010-2011 Matthias Pueski
       
   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.
    
*/

import java.net.URL;

import javax.swing.ImageIcon;

public class Main {
    /**
     * Create an ImageIcon from the image at the specified path
     * 
     * @param path The path of the image
     * 
     * @return The image icon, or null if the image doesn't exist
     */
    public static ImageIcon createImageIcon(String path) {

        URL u = Thread.currentThread().getContextClassLoader().getResource(path);

        // TODO : Check if that works with webstart

        // URL u = ClassLoader.getSystemResource(realPath);//UIUtils.class.getResource(path);

        if (u == null)
            return null;
        return new ImageIcon(u);
    }
}

Related

  1. createImageIcon(final String src)
  2. createImageIcon(java.net.URL imgURL)
  3. createImageIcon(String iconFile)
  4. createImageIcon(String imgFile)
  5. createImageIcon(String path)
  6. createImageIcon(String path)
  7. createImageIcon(String path)
  8. createImageIcon(String path, Class resourceClass)
  9. createImageIcon(String path, Class c)