public class ImageIcon extends Objectimplements Icon , Serializable , Accessible
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 JavaBeans™ has been added to the java.beans package. Please see XMLEncoder.
| Modifier and Type | Class and Description |
|---|---|
protected class |
ImageIcon
This class implements accessibility support for the
ImageIcon class.
|
| Modifier and Type | Field and Description |
|---|---|
protected static Component |
component
Deprecated.
since 1.8
|
protected static MediaTracker |
tracker
Deprecated.
since 1.8
|
| Constructor and 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
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
Creates an ImageIcon from an image object.
|
ImageIcon(Image
Creates an ImageIcon from the image.
|
ImageIcon(String
Creates an ImageIcon from the specified file.
|
ImageIcon(String
Creates an ImageIcon from the specified file.
|
ImageIcon(URL
Creates an ImageIcon from the specified URL.
|
ImageIcon(URL
Creates an ImageIcon from the specified URL.
|
| Modifier and Type | Method and 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
Loads the image, returning only when the image is loaded.
|
void |
paintIcon(Component
Paints the icon.
|
void |
setDescription(String
Sets the description of the image.
|
void |
setImage(Image
Sets the image displayed by this icon.
|
void |
setImageObserver(ImageObserver
Sets the image observer for the image.
|
String |
toString()
Returns a string representation of this image.
|
@Deprecated protected static final Componentcomponent
@Deprecated protected static final MediaTrackertracker
public ImageIcon(Stringfilename, String description)
filename - the name of the file containing the image
description - a brief textual description of the image
ImageIcon(String)
@ConstructorProperties(value="description") public ImageIcon(Stringfilename)
new ImageIcon("images/myImage.gif") The description is initialized to the
filename string.
filename - a String specifying a filename or path
getDescription()
public ImageIcon(URLlocation, String description)
location - the URL for the image
description - a brief textual description of the image
ImageIcon(String)
public ImageIcon(URLlocation)
location - the URL for the image
getDescription()
public ImageIcon(Imageimage, String description)
image - the image
description - a brief textual description of the image
public ImageIcon(Imageimage)
image - the image
getDescription(),
Image.getProperty(java.lang.String, java.awt.image.ImageObserver)
public ImageIcon(byte[] imageData,
String description)
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
Toolkit.createImage(java.lang.String)
public ImageIcon(byte[] imageData)
imageData - an array of pixels in an image format supported by the AWT Toolkit, such as GIF, JPEG, or (as of 1.3) PNG
Toolkit.createImage(java.lang.String) ,
getDescription(),
Image.getProperty(java.lang.String, java.awt.image.ImageObserver)
public ImageIcon()
protected void loadImage(Imageimage)
image - the image
public int getImageLoadStatus()
MediaTracker.ABORTED ,
MediaTracker.ERRORED ,
MediaTracker.COMPLETE
public ImagegetImage()
Image.
Image object for this
ImageIcon
public void setImage(Imageimage)
image - the image
public StringgetDescription()
public void setDescription(Stringdescription)
description - a brief textual description of the image
public void paintIcon(Componentc, 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.
public int getIconWidth()
getIconWidth in interface
Icon
public int getIconHeight()
getIconHeight in interface
Icon
public void setImageObserver(ImageObserverobserver)
icon = new ImageIcon(...)
button.setIcon(icon);
icon.setImageObserver(button);
observer - the image observer
public ImageObservergetImageObserver()
public StringtoString()
public AccessibleContextgetAccessibleContext()
getAccessibleContext in interface
Accessible