ImageIcon (Java SE 15 & JDK 15) (original) (raw)

All Implemented Interfaces:

[Serializable](../../../java.base/java/io/Serializable.html "interface in java.io"), [Accessible](../accessibility/Accessible.html "interface in javax.accessibility"), [Icon](Icon.html "interface in javax.swing")


public class ImageIcon extends Object implements Icon, Serializable, Accessible

An implementation of the Icon interface that paints Icons from Images. Images that are created from a URL, filename or byte array are preloaded using MediaTracker to monitor the loaded state of the image.

For further information and examples of using image icons, seeHow to Use Icons in The Java Tutorial.

Warning: Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. As of 1.4, support for long term storage of all JavaBeans has been added to the java.beans package. Please see XMLEncoder.

Since:

1.2

Nested Classes

Modifier and Type Class Description
protected class ImageIcon.AccessibleImageIcon This class implements accessibility support for theImageIcon class.

Fields

Modifier and Type Field Description
protected static Component component Deprecated.
protected static MediaTracker tracker Deprecated.

Constructors

Constructor Description
ImageIcon() Creates an uninitialized image icon.
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.
ImageIcon​(byte[] imageData,String 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.
ImageIcon​(Image image) Creates an ImageIcon from an image object.
ImageIcon​(Image image,String description) Creates an ImageIcon from the image.
ImageIcon​(String filename) Creates an ImageIcon from the specified file.
ImageIcon​(String filename,String description) Creates an ImageIcon from the specified file.
ImageIcon​(URL location) Creates an ImageIcon from the specified URL.
ImageIcon​(URL location,String description) Creates an ImageIcon from the specified URL.
Modifier and Type Method Description
AccessibleContext getAccessibleContext() Gets the AccessibleContext associated with this ImageIcon.
String getDescription() Gets the description of the image.
int getIconHeight() Gets the height of the icon.
int getIconWidth() Gets the width of the icon.
Image getImage() Returns this icon's Image.
int getImageLoadStatus() Returns the status of the image loading operation.
ImageObserver getImageObserver() Returns the image observer for the image.
protected void loadImage​(Image image) Loads the image, returning only when the image is loaded.
void paintIcon​(Component c,Graphics g, int x, int y) Paints the icon.
void setDescription​(String description) Sets the description of the image.
void setImage​(Image image) Sets the image displayed by this icon.
void setImageObserver​(ImageObserver observer) Sets the image observer for the image.
String toString() Returns a string representation of this image.