Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| Swing 1.1
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## javax.swing
Class ImageIcon

    java.lang.Object
      |
      +--javax.swing.ImageIcon

public class ImageIcon
extends java.lang.Object
implements Icon, java.io.Serializable

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

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. A future release of Swing will provide support for long term persistence.

See Also:
  Serialized Form

Field Summary
`protected static java.awt.Component` | `component`
`protected static java.awt.MediaTracker` | `tracker`

Constructor Summary
`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 or JPEG.
`ImageIcon(byte[] imageData, java.lang.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 or JPEG.
`ImageIcon(java.awt.Image image)` Creates an ImageIcon from an image object.
`ImageIcon(java.awt.Image image, java.lang.String description)` Creates an ImageIcon from the image.
`ImageIcon(java.lang.String filename)` Creates an ImageIcon from the specified file.
`ImageIcon(java.lang.String filename, java.lang.String description)` Creates an ImageIcon from the specified file.
`ImageIcon(java.net.URL location)` Creates an ImageIcon from the specified URL.
`ImageIcon(java.net.URL location, java.lang.String description)` Creates an ImageIcon from the specified URL.

Method Summary
`java.lang.String` | `getDescription()` Get the description of the image.
`int` | `getIconHeight()` Get the height of the Icon
`int` | `getIconWidth()` Get the width of the Icon
`java.awt.Image` | `getImage()` Returns the Icon's Image
`int` | `getImageLoadStatus()` Returns the status of the image loading operation.
`java.awt.image.ImageObserver` | `getImageObserver()` Return the umage observer for the image
`protected void` | `loadImage(java.awt.Image image)` Wait for the image to load
`void` | `paintIcon(java.awt.Component c, java.awt.Graphics g, int x, int y)` Paints the Icon
`void` | `setDescription(java.lang.String description)` Set the description of the image.
`void` | `setImage(java.awt.Image image)` Set the image displayed by this icon.
`void` | `setImageObserver(java.awt.image.ImageObserver observer)` Set the image observer for the image.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### component

    protected static final java.awt.Component component

### tracker

    protected static final java.awt.MediaTracker tracker

Constructor Detail

### ImageIcon

    public ImageIcon(java.lang.String filename,
                     java.lang.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.
  Parameters:
    `filename` - the name of the file containing the image
    `description` - a brief textual description of the image
  See Also:
    `ImageIcon(String)`

### ImageIcon

    public ImageIcon(java.lang.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. For example, specify:

          new ImageIcon("images/myImage.gif")

  (The string is converted to an URL, so the forward-slash works on all systems.)
  Parameters:
    `filename` - a String specifying a filename or path

### ImageIcon

    public ImageIcon(java.net.URL location,
                     java.lang.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.
  Parameters:
    `URL` - the URL for the image
    `description` - a brief textual description of the image
  See Also:
    `ImageIcon(String)`

### ImageIcon

    public ImageIcon(java.net.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.

### ImageIcon

    public ImageIcon(java.awt.Image image,
                     java.lang.String description)

  Creates an ImageIcon from the image.
  Parameters:
    `image` - the image
    `description` - a brief textual description of the image

### ImageIcon

    public ImageIcon(java.awt.Image image)

  Creates an ImageIcon from an image object.

### ImageIcon

    public ImageIcon(byte[] imageData,
                     java.lang.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 or JPEG. 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 or JPEG.
    `description` - a brief textual description of the image
  See Also:
    `Toolkit.createImage(java.awt.image.ImageProducer)`

### 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 or JPEG. 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:
    `an` - array of pixels in an image format supported by the AWT Toolkit, such as GIF or JPEG.
  See Also:
    `Toolkit.createImage(java.awt.image.ImageProducer)`

### ImageIcon

    public ImageIcon()

  Creates an uninitialized image icon.

Method Detail

### loadImage

    protected void loadImage(java.awt.Image image)

  Wait for the image to load

### 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`, `MediaTracker.ERRORED`, `MediaTracker.COMPLETE`

### getImage

    public java.awt.Image getImage()

  Returns the Icon's Image

### setImage

    public void setImage(java.awt.Image image)

  Set the image displayed by this icon.

### getDescription

    public java.lang.String getDescription()

  Get 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.

### setDescription

    public void setDescription(java.lang.String description)

  Set 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.

### paintIcon

    public void paintIcon(java.awt.Component c,
                          java.awt.Graphics g,
                          int x,
                          int y)

  Paints the Icon
  Specified by:
    paintIcon in interface Icon

### getIconWidth

    public int getIconWidth()

  Get the width of the Icon
  Specified by:
    getIconWidth in interface Icon

### getIconHeight

    public int getIconHeight()

  Get the height of the Icon
  Specified by:
    getIconHeight in interface Icon

### setImageObserver

    public void setImageObserver(java.awt.image.ImageObserver observer)

  Set 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);

### getImageObserver

    public java.awt.image.ImageObserver getImageObserver()

  Return the umage observer for the image

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| Swing 1.1
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Submit a bug or feature
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries.
Copyright 1993-1998 Sun Microsystems, Inc. 901 San Antonio Road,
Palo Alto, California, 94303, U.S.A. All Rights Reserved.