Java JButton Settings hasIcon(AbstractButton button)

Here you can find the source of hasIcon(AbstractButton button)

Description

Checks whether the specified button has associated icon.

License

Open Source License

Parameter

Parameter Description
button Button.

Return

If the button has associated icon, true is returned, otherwise false.

Declaration

public static boolean hasIcon(AbstractButton button) 

Method Source Code

//package com.java2s;

import java.net.URL;

import javax.swing.*;
import javax.swing.plaf.*;

public class Main {
    /**// w  w w  .ja  v  a 2  s.  c o m
     * Checks whether the specified button has associated icon.
     * 
     * @param button
     *            Button.
     * @return If the button has associated icon, <code>true</code> is returned,
     *         otherwise <code>false</code>.
     */
    public static boolean hasIcon(AbstractButton button) {
        return (button.getIcon() != null);
    }

    /**
     * Returns an icon pointed to by the specified string.
     * 
     * @param iconResource
     *            Resource location string.
     * @return Icon.
     */
    public static Icon getIcon(String iconResource) {
        ClassLoader cl = getClassLoaderForResources();
        URL iconUrl = cl.getResource(iconResource);
        if (iconUrl == null)
            return null;
        return new IconUIResource(new ImageIcon(iconUrl));
    }

    /**
     * Returns the class loader for loading the resource files. It is a fix by
     * Dag Joar and Christian Schlichtherle for application running with
     * -Xbootclasspath VM flag. In this case, the using
     * MyClass.class.getClassLoader() would return null, but the context class
     * loader will function properly that classes will be properly loaded
     * regardless of whether the lib is added to the system class path, the
     * extension class path and regardless of the class loader architecture set
     * up by some frameworks.
     * 
     * @return The class loader for loading the resource files.
     */
    public static ClassLoader getClassLoaderForResources() {
        ClassLoader cl = (ClassLoader) UIManager.get("ClassLoader");
        if (cl == null)
            cl = Thread.currentThread().getContextClassLoader();
        return cl;
    }
}

Related

  1. getTogglableIconButton(ImageIcon icon)
  2. getWindowFileChooserOKButton(JFileChooser chooser)
  3. groupButtons(AbstractButton... buttons)
  4. groupButtons(final Container container, final boolean recursive)
  5. growFont(JComponent button)
  6. hasText(AbstractButton button)
  7. hideApproveButton(JFileChooser fileChooser)
  8. hideJFileChooserButtons(JFileChooser sessionFileChooser)
  9. interButtonSpace()