Java Swing Icon loadIcon(String resourceName)

Here you can find the source of loadIcon(String resourceName)

Description

Loads an icon from a resource.

License

Open Source License

Parameter

Parameter Description
resourceName the name of the resource to load.

Return

the icon named by the specified resource, or null if the resource could not be found or loaded.

Declaration

public static Icon loadIcon(String resourceName) 

Method Source Code

//package com.java2s;
/*/*ww w.  j  a  va  2 s  .  c  o  m*/
 * ResourceUtilities.java (Class: com.madphysicist.tools.util.ResourceUtilities)
 *
 * Mad Physicist JTools Project (General Purpose Utilities)
 *
 * The MIT License (MIT)
 *
 * Copyright (c) 2013 by Joseph Fox-Rabinovitz
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

import java.net.URL;

import javax.swing.Icon;
import javax.swing.ImageIcon;

public class Main {
    /**
     * Loads an icon from a resource. This method can load animated GIFs in addition
     * to regular icons. It returns {@code null} instead of throwing an exception.
     *
     * @param resourceName the name of the resource to load.
     * @return the icon named by the specified resource, or {@code null} if the resource could not be found or loaded.
     * @since 1.0.2
     */
    public static Icon loadIcon(String resourceName) {
        URL url = ClassLoader.getSystemResource(resourceName);
        return (url == null) ? null : new ImageIcon(url);
    }
}

Related

  1. iconFromStream(final InputStream in)
  2. item(String name, Icon icon)
  3. loadIcon(Class pRootClass, String strPath)
  4. loadIcon(ClassLoader classLoader, String path)
  5. loadIcon(String icon)
  6. loadIcons(String list, String path, Set ignore, ClassLoader loader)
  7. loadLoadingIcon()
  8. makeButtcon(Icon icon, Icon rollover, String tooltip, boolean is_toggle)
  9. mergeComponentAndIcon(JComponent component, Icon icon)