java.lang.Objectjavax.swing.ImageIcon
public class ImageIcon
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 JavaBeans TM has been added to the java.beans package. Please see XMLEncoder .
Nested Class Summary | |
---|---|
protected class |
ImageIcon.AccessibleImageIcon
This class implements accessibility support for the ImageIcon class. |
Field Summary | |
---|---|
protected static Component |
component
|
protected static 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, 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. |
Method Summary | |
---|---|
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. |
Methods inherited from class java.lang. Object |
---|
clone , equals , finalize , getClass , hashCode , notify , notifyAll , wait , wait , wait |
Field Detail |
---|
protected static final Component component
protected static final MediaTracker tracker
Constructor Detail |
---|
public ImageIcon(String filename, String description)
public ImageIcon(String filename)
new ImageIcon("images/myImage.gif")The description is initialized to the filename string.
public ImageIcon(URL location, String description)
public ImageIcon(URL location)
public ImageIcon(Image image, String description)
public ImageIcon(Image image)
public ImageIcon(byte[] imageData, String description)
public ImageIcon(byte[] imageData)
public ImageIcon()
Method Detail |
---|
protected void loadImage(Image image)
public int getImageLoadStatus()
public Image getImage()
public void setImage(Image image)
public String getDescription()
public void setDescription(String description)
public void paintIcon(Component c, Graphics g, int x, int y)
public int getIconWidth()
public int getIconHeight()
public void setImageObserver(ImageObserver observer)
icon = new ImageIcon(...) button.setIcon(icon); icon.setImageObserver(button);
public ImageObserver getImageObserver()
public String toString()
public AccessibleContext getAccessibleContext()