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, see
How 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 JavaBeansTM
has been added to the java.beans package.
Please see java.beans.XMLEncoder.
| Constructors |
| public |
ImageIcon(String filename, String description) Creates an ImageIcon from the specified file. The image will
be preloaded by using MediaTracker to monitor the loading state
of the image.
| filename | the name of the file containing the image |
| description | a brief textual description of the image |
| See also | ImageIcon(String) |
|
| public |
ImageIcon(String 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.
| filename | a String specifying a filename or path |
| See also | getDescription |
|
| public |
ImageIcon(URL location, String description) Creates an ImageIcon from the specified URL. The image will
be preloaded by using MediaTracker to monitor the loaded state
of the image.
| location | the URL for the image |
| description | a brief textual description of the image |
| See also | ImageIcon(String) |
|
| public |
ImageIcon(URL 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.
|
| public |
ImageIcon(Image image, String description) Creates an ImageIcon from the image.
| image | the image |
| description | a brief textual description of the image |
|
| public |
ImageIcon(Image 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.
|
| public |
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.
Normally this array is created
by reading an image using Class.getResourceAsStream(), but
the byte array may also be statically stored in a class.
| 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 | createImage |
|
| 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.
|
| public |
ImageIcon() Creates an uninitialized image icon.
|
| Properties |
| public AccessibleContext |
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.
| return | an AccessibleImageIcon that serves as the
AccessibleContext of this ImageIcon |
| beaninfo | expert: true
description: The AccessibleContext associated with this ImageIcon. |
| since | 1.3 |
|
| public void |
setDescription(String 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.
| description | a brief textual description of the image |
|
| public String |
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.
| return | a brief textual description of the image |
|
| public int |
getIconHeight() Gets the height of the icon.
| return | the height in pixels of this icon |
|
| public int |
getIconWidth() Gets the width of the icon.
| return | the width in pixels of this icon |
|
| public void |
setImage(Image image) Sets the image displayed by this icon.
|
| public Image |
getImage() Returns this icon's Image.
| return | the Image object for this ImageIcon |
|
| public int |
getImageLoadStatus() Returns the status of the image loading operation.
|
| public void |
setImageObserver(ImageObserver 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);
| observer | the image observer |
|
| public ImageObserver |
getImageObserver() Returns the image observer for the image.
| return | the image observer, which may be null |
|