* #### component
[@Deprecated](../../../java.base/java/lang/Deprecated.html "annotation in java.lang")
protected static final [Component](../../java/awt/Component.html "class in java.awt") component
Do not use this shared component, which is used to track image loading. It is left for backward compatibility only.
* #### tracker
[@Deprecated](../../../java.base/java/lang/Deprecated.html "annotation in java.lang")
protected static final [MediaTracker](../../java/awt/MediaTracker.html "class in java.awt") tracker
Do not use this shared media tracker, which is used to load images. It is left for backward compatibility only.
Constructor Detail
* #### ImageIcon
public ImageIcon([String](../../../java.base/java/lang/String.html "class in java.lang") filename,
[String](../../../java.base/java/lang/String.html "class in java.lang") description)
Creates an ImageIcon from the specified file. The image will be preloaded by using MediaTracker to monitor the loading state of the image.
Parameters:
`filename` \- the name of the file containing the image
`description` \- a brief textual description of the image
See Also:
[ImageIcon(String)](#%3Cinit%3E%28java.lang.String%29)
* #### ImageIcon
[@ConstructorProperties](../../java/beans/ConstructorProperties.html "annotation in java.beans")("description")
public ImageIcon([String](../../../java.base/java/lang/String.html "class in java.lang") filename)
Creates an ImageIcon from the specified file. The image will be preloaded by using MediaTracker to monitor the loading state of the image. The specified String can be a file name or a file path. When specifying a path, use the Internet-standard forward-slash ("/") as a separator. (The string is converted to an URL, so the forward-slash works on all systems.) For example, specify:
new ImageIcon("images/myImage.gif")
The description is initialized to the `filename` string.
Parameters:
`filename` \- a String specifying a filename or path
See Also:
[getDescription()](#getDescription%28%29)
* #### ImageIcon
public ImageIcon([URL](../../../java.base/java/net/URL.html "class in java.net") location,
[String](../../../java.base/java/lang/String.html "class in java.lang") description)
Creates an ImageIcon from the specified URL. The image will be preloaded by using MediaTracker to monitor the loaded state of the image.
Parameters:
`location` \- the URL for the image
`description` \- a brief textual description of the image
See Also:
[ImageIcon(String)](#%3Cinit%3E%28java.lang.String%29)
* #### ImageIcon
public ImageIcon([URL](../../../java.base/java/net/URL.html "class in java.net") location)
Creates an ImageIcon from the specified URL. The image will be preloaded by using MediaTracker to monitor the loaded state of the image. The icon's description is initialized to be a string representation of the URL.
Parameters:
`location` \- the URL for the image
See Also:
[getDescription()](#getDescription%28%29)
* #### ImageIcon
public ImageIcon([Image](../../java/awt/Image.html "class in java.awt") image,
[String](../../../java.base/java/lang/String.html "class in java.lang") description)
Creates an ImageIcon from the image.
Parameters:
`image` \- the image
`description` \- a brief textual description of the image
* #### ImageIcon
public ImageIcon([Image](../../java/awt/Image.html "class in java.awt") image)
Creates an ImageIcon from an image object. If the image has a "comment" property that is a string, then the string is used as the description of this icon.
Parameters:
`image` \- the image
See Also:
[getDescription()](#getDescription%28%29), [Image.getProperty(java.lang.String, java.awt.image.ImageObserver)](../../java/awt/Image.html#getProperty%28java.lang.String,java.awt.image.ImageObserver%29)
* #### ImageIcon
public ImageIcon(byte[] imageData,
[String](../../../java.base/java/lang/String.html "class in java.lang") description)
Creates an ImageIcon from an array of bytes which were read from an image file containing a supported image format, such as GIF, JPEG, or (as of 1.3) PNG. Normally this array is created by reading an image using Class.getResourceAsStream(), but the byte array may also be statically stored in a class.
Parameters:
`imageData` \- an array of pixels in an image format supported by the AWT Toolkit, such as GIF, JPEG, or (as of 1.3) PNG
`description` \- a brief textual description of the image
See Also:
[Toolkit.createImage(java.lang.String)](../../java/awt/Toolkit.html#createImage%28java.lang.String%29)
* #### ImageIcon
public ImageIcon(byte[] imageData)
Creates an ImageIcon from an array of bytes which were read from an image file containing a supported image format, such as GIF, JPEG, or (as of 1.3) PNG. Normally this array is created by reading an image using Class.getResourceAsStream(), but the byte array may also be statically stored in a class. If the resulting image has a "comment" property that is a string, then the string is used as the description of this icon.
Parameters:
`imageData` \- an array of pixels in an image format supported by the AWT Toolkit, such as GIF, JPEG, or (as of 1.3) PNG
See Also:
[Toolkit.createImage(java.lang.String)](../../java/awt/Toolkit.html#createImage%28java.lang.String%29), [getDescription()](#getDescription%28%29), [Image.getProperty(java.lang.String, java.awt.image.ImageObserver)](../../java/awt/Image.html#getProperty%28java.lang.String,java.awt.image.ImageObserver%29)
* #### ImageIcon
public ImageIcon()
Creates an uninitialized image icon.
Method Detail
* #### loadImage
protected void loadImage([Image](../../java/awt/Image.html "class in java.awt") image)
Loads the image, returning only when the image is loaded.
Parameters:
`image` \- the image
* #### getImageLoadStatus
public int getImageLoadStatus()
Returns the status of the image loading operation.
Returns:
the loading status as defined by java.awt.MediaTracker
See Also:
[MediaTracker.ABORTED](../../java/awt/MediaTracker.html#ABORTED), [MediaTracker.ERRORED](../../java/awt/MediaTracker.html#ERRORED), [MediaTracker.COMPLETE](../../java/awt/MediaTracker.html#COMPLETE)
* #### getImage
public [Image](../../java/awt/Image.html "class in java.awt") getImage()
Returns this icon's `Image`.
Returns:
the `Image` object for this `ImageIcon`
* #### setImage
public void setImage([Image](../../java/awt/Image.html "class in java.awt") image)
Sets the image displayed by this icon.
Parameters:
`image` \- the image
* #### getDescription
public [String](../../../java.base/java/lang/String.html "class in java.lang") getDescription()
Gets the description of the image. This is meant to be a brief textual description of the object. For example, it might be presented to a blind user to give an indication of the purpose of the image. The description may be null.
Returns:
a brief textual description of the image
* #### setDescription
public void setDescription([String](../../../java.base/java/lang/String.html "class in java.lang") description)
Sets the description of the image. This is meant to be a brief textual description of the object. For example, it might be presented to a blind user to give an indication of the purpose of the image.
Parameters:
`description` \- a brief textual description of the image
* #### paintIcon
public void paintIcon([Component](../../java/awt/Component.html "class in java.awt") c,
[Graphics](../../java/awt/Graphics.html "class in java.awt") g,
int x,
int y)
Paints the icon. The top-left corner of the icon is drawn at the point (`x`, `y`) in the coordinate space of the graphics context `g`. If this icon has no image observer, this method uses the `c` component as the observer.
Specified by:
`[paintIcon](Icon.html#paintIcon%28java.awt.Component,java.awt.Graphics,int,int%29)` in interface `[Icon](Icon.html "interface in javax.swing")`
Parameters:
`c` \- the component to be used as the observer if this icon has no image observer
`g` \- the graphics context
`x` \- the X coordinate of the icon's top-left corner
`y` \- the Y coordinate of the icon's top-left corner
* #### getIconWidth
public int getIconWidth()
Gets the width of the icon.
Specified by:
`[getIconWidth](Icon.html#getIconWidth%28%29)` in interface `[Icon](Icon.html "interface in javax.swing")`
Returns:
the width in pixels of this icon
* #### getIconHeight
public int getIconHeight()
Gets the height of the icon.
Specified by:
`[getIconHeight](Icon.html#getIconHeight%28%29)` in interface `[Icon](Icon.html "interface in javax.swing")`
Returns:
the height in pixels of this icon
* #### setImageObserver
public void setImageObserver([ImageObserver](../../java/awt/image/ImageObserver.html "interface in java.awt.image") observer)
Sets the image observer for the image. Set this property if the ImageIcon contains an animated GIF, so the observer is notified to update its display. For example:
icon = new ImageIcon(...)
button.setIcon(icon);
icon.setImageObserver(button);
Parameters:
`observer` \- the image observer
* #### getImageObserver
public [ImageObserver](../../java/awt/image/ImageObserver.html "interface in java.awt.image") getImageObserver()
Returns the image observer for the image.
Returns:
the image observer, which may be null
* #### toString
public [String](../../../java.base/java/lang/String.html "class in java.lang") toString()
Returns a string representation of this image.
Overrides:
`[toString](../../../java.base/java/lang/Object.html#toString%28%29)` in class `[Object](../../../java.base/java/lang/Object.html "class in java.lang")`
Returns:
a string representing this image
* #### getAccessibleContext
[@BeanProperty](../../java/beans/BeanProperty.html "annotation in java.beans")([expert](../../java/beans/BeanProperty.html#expert%28%29)=true,
[description](../../java/beans/BeanProperty.html#description%28%29)="The AccessibleContext associated with this ImageIcon.")
public [AccessibleContext](../accessibility/AccessibleContext.html "class in javax.accessibility") getAccessibleContext()
Gets the AccessibleContext associated with this ImageIcon. For image icons, the AccessibleContext takes the form of an AccessibleImageIcon. A new AccessibleImageIcon instance is created if necessary.
Specified by:
`[getAccessibleContext](../accessibility/Accessible.html#getAccessibleContext%28%29)` in interface `[Accessible](../accessibility/Accessible.html "interface in javax.accessibility")`
Returns:
an AccessibleImageIcon that serves as the AccessibleContext of this ImageIcon
Since:
1.3