public class ImageIconAWT extends java.lang.Object implements IconAWT
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 XMLEncoder.
| Modifier and Type | Field and Description |
|---|---|
protected static java.awt.Component |
component |
protected static java.awt.MediaTracker |
tracker |
| Constructor and Description |
|---|
ImageIconAWT()
Creates an uninitialized image icon.
|
ImageIconAWT(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.
|
ImageIconAWT(java.awt.Image image)
Creates an ImageIcon from an image object.
|
ImageIconAWT(java.lang.String filename)
Creates an ImageIcon from the specified file.
|
ImageIconAWT(java.net.URL location)
Creates an ImageIcon from the specified URL.
|
| Modifier and Type | Method and Description |
|---|---|
int |
getIconHeight()
Gets the height of the icon.
|
int |
getIconWidth()
Gets the width of the icon.
|
java.awt.Image |
getImage()
Returns this icon's
Image. |
int |
getImageLoadStatus()
Returns the status of the image loading operation.
|
java.awt.image.ImageObserver |
getImageObserver()
Returns the image observer for the image.
|
protected void |
loadImage(java.awt.Image image)
Loads the image, returning only when the image is loaded.
|
void |
paintIcon(java.awt.Component c,
java.awt.Graphics g,
int x,
int y)
Paints the icon.
|
void |
setImage(java.awt.Image image)
Sets the image displayed by this icon.
|
void |
setImageObserver(java.awt.image.ImageObserver observer)
Sets the image observer for the image.
|
protected static final java.awt.Component component
protected static final java.awt.MediaTracker tracker
public ImageIconAWT(java.lang.String filename)
filename - the name of the file containing the imagepublic ImageIconAWT(java.net.URL location)
location - the URL for the imagepublic ImageIconAWT(java.awt.Image image)
image - the imageImage.getProperty(java.lang.String, java.awt.image.ImageObserver)public ImageIconAWT(byte[] imageData)
imageData - an array of pixels in an image format supported
by the AWT Toolkit, such as GIF or JPEG.Toolkit.createImage(java.lang.String)public ImageIconAWT()
protected void loadImage(java.awt.Image image)
image - the imagepublic int getImageLoadStatus()
MediaTracker.ABORTED,
MediaTracker.ERRORED,
MediaTracker.COMPLETEpublic java.awt.Image getImage()
Image.Image object for this ImageIconpublic void setImage(java.awt.Image image)
image - the imagepublic void paintIcon(java.awt.Component c,
java.awt.Graphics g,
int x,
int y)
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.paintIcon in interface IconAWTpaintIcon in interface javax.swing.Iconc - the component to be used as the observer
if this icon has no image observerg - the graphics contextx - the X coordinate of the icon's top-left cornery - the Y coordinate of the icon's top-left cornerpublic int getIconWidth()
getIconWidth in interface IconAWTgetIconWidth in interface javax.swing.Iconpublic int getIconHeight()
getIconHeight in interface IconAWTgetIconHeight in interface javax.swing.Iconpublic void setImageObserver(java.awt.image.ImageObserver observer)
icon = new ImageIcon(...)
button.setIcon(icon);
icon.setImageObserver(button);
observer - the image observerpublic java.awt.image.ImageObserver getImageObserver()