- java.lang.Object
 -  
      
- javax.swing.ImageIcon
 
 
-  
       
- 实现的所有接口
 -  
         
Serializable,Accessible,Icon 
public class ImageIcon extends Object implements Icon, Serializable, Accessible
Icon界面的一个实现,用于绘制图像中的图标。 使用MediaTracker预先加载从URL,文件名或字节数组创建的图像,以监视图像的加载状态。有关使用图像图标的更多信息和示例,请参阅The Java Tutorial中的 How to Use Icons 。
警告:此类的序列化对象与以后的Swing版本不兼容。 当前的序列化支持适用于运行相同版本Swing的应用程序之间的短期存储或RMI。 从1.4开始,
java.beans软件包中添加了对所有JavaBeansjava.beans长期存储的支持。 请参阅XMLEncoder。- 从以下版本开始:
 - 1.2
 - 另请参见:
 - Serialized Form
 
 
-  
        
       
-  
             
嵌套类汇总
嵌套类 变量和类型 类 描述 protected classImageIcon.AccessibleImageIcon此类实现ImageIcon类的可访问性支持。 
-  
             
字段汇总
字段 变量和类型 字段 描述 protected static Componentcomponent已过时。从1.8开始protected static MediaTrackertracker已过时。从1.8开始 
-  
             
构造方法摘要
构造方法 构造器 描述 ImageIcon()创建未初始化的图像图标。ImageIcon(byte[] imageData)从包含支持的图像格式的图像文件(例如GIF,JPEG或(从1.3开始)PNG)读取的字节数组创建ImageIcon。ImageIcon(byte[] imageData, String description)从包含支持的图像格式的图像文件(例如GIF,JPEG或(从1.3开始)PNG)读取的字节数组创建ImageIcon。ImageIcon(Image image)从图像对象创建ImageIcon。ImageIcon(Image image, String description)从图像创建ImageIcon。ImageIcon(String filename)从指定的文件创建ImageIcon。ImageIcon(String filename, String description)从指定的文件创建ImageIcon。ImageIcon(URL location)从指定的URL创建ImageIcon。ImageIcon(URL location, String description)从指定的URL创建ImageIcon。 
-  
             
方法摘要
所有方法 实例方法 具体的方法 变量和类型 方法 描述 AccessibleContextgetAccessibleContext()获取与此ImageIcon关联的AccessibleContext。StringgetDescription()获取图像的描述。intgetIconHeight()获取图标的高度。intgetIconWidth()获取图标的宽度。ImagegetImage()返回此图标的Image。intgetImageLoadStatus()返回图像加载操作的状态。ImageObservergetImageObserver()返回图像的图像观察者。protected voidloadImage(Image image)加载图像,仅在加载图像时返回。voidpaintIcon(Component c, Graphics g, int x, int y)绘制图标。voidsetDescription(String description)设置图像的描述。voidsetImage(Image image)设置此图标显示的图像。voidsetImageObserver(ImageObserver observer)设置图像的图像观察者。StringtoString()返回此图像的字符串表示形式。 
 -  
             
 
-  
        
       
-  
             
字段详细信息
-  
component
@Deprecated protected static final Component component
Deprecated.since 1.8请勿使用此共享组件,该组件用于跟踪图像加载。 它仅用于向后兼容。 
-  
tracker
@Deprecated protected static final MediaTracker tracker
Deprecated.since 1.8请勿使用此共享媒体跟踪器,该跟踪器用于加载图像。 它仅用于向后兼容。 
 -  
 
-  
             
构造方法详细信息
-  
ImageIcon
public ImageIcon(String filename, String description)
从指定的文件创建ImageIcon。 将使用MediaTracker预先加载图像以监控图像的加载状态。- 参数
 -  
              
filename- 包含图像的文件的名称 -  
              
description- 图像的简短文字说明 - 另请参见:
 -  
              
ImageIcon(String) 
 
-  
ImageIcon
@ConstructorProperties("description") public ImageIcon(String filename)
从指定的文件创建ImageIcon。 将使用MediaTracker预先加载图像以监控图像的加载状态。 指定的String可以是文件名或文件路径。 指定路径时,请使用Internet标准正斜杠(“/”)作为分隔符。 (该字符串将转换为URL,因此正斜杠适用于所有系统。)例如,指定:new ImageIcon("images/myImage.gif")描述初始化为filename字符串。- 参数
 -  
              
filename- 指定文件名或路径的String - 另请参见:
 -  
              
getDescription() 
 
-  
ImageIcon
public ImageIcon(URL location, String description)
从指定的URL创建ImageIcon。 将使用MediaTracker预先加载图像以监视图像的加载状态。- 参数
 -  
              
location- 图像的URL -  
              
description- 图像的简短文字说明 - 另请参见:
 -  
              
ImageIcon(String) 
 
-  
ImageIcon
public ImageIcon(URL location)
从指定的URL创建ImageIcon。 将使用MediaTracker预先加载图像以监视图像的加载状态。 图标的描述被初始化为URL的字符串表示。- 参数
 -  
              
location- 图像的URL - 另请参见:
 -  
              
getDescription() 
 
-  
ImageIcon
public ImageIcon(Image image, String description)
从图像创建ImageIcon。- 参数
 -  
              
image- 图像 -  
              
description- 图像的简短文字说明 
 
-  
ImageIcon
public ImageIcon(Image image)
从图像对象创建ImageIcon。 如果图像具有作为字符串的“comment”属性,则该字符串将用作此图标的描述。- 参数
 -  
              
image- 图像 - 另请参见:
 -  
              
getDescription(),Image.getProperty(java.lang.String, java.awt.image.ImageObserver) 
 
-  
ImageIcon
public ImageIcon(byte[] imageData, String description)从包含支持的图像格式的图像文件(例如GIF,JPEG或(从1.3开始)PNG)读取的字节数组创建ImageIcon。 通常,此数组是使用Class.getResourceAsStream()读取图像创建的,但字节数组也可以静态存储在类中。- 参数
 -  
              
imageData- AWT工具包支持的图像格式的像素数组,例如GIF,JPEG或(从1.3开始)PNG -  
              
description- 图像的简短文字说明 - 另请参见:
 -  
              
Toolkit.createImage(java.lang.String) 
 
-  
ImageIcon
public ImageIcon(byte[] imageData)
从包含支持的图像格式的图像文件(例如GIF,JPEG或(从1.3开始)PNG)读取的字节数组创建ImageIcon。 通常,此数组是使用Class.getResourceAsStream()读取图像创建的,但字节数组也可以静态存储在类中。 如果生成的图像具有字符串的“comment”属性,则该字符串将用作此图标的描述。- 参数
 -  
              
imageData- AWT工具包支持的图像格式的像素数组,例如GIF,JPEG或(从1.3开始)PNG - 另请参见:
 -  
              
Toolkit.createImage(java.lang.String),getDescription(),Image.getProperty(java.lang.String, java.awt.image.ImageObserver) 
 
-  
ImageIcon
public ImageIcon()
创建未初始化的图像图标。 
 -  
 
-  
             
方法详细信息
-  
loadImage
protected void loadImage(Image image)
加载图像,仅在加载图像时返回。- 参数
 -  
              
image- 图像 
 
-  
getImageLoadStatus
public int getImageLoadStatus()
返回图像加载操作的状态。- 结果
 - 由java.awt.MediaTracker定义的加载状态
 - 另请参见:
 -  
              
MediaTracker.ABORTED,MediaTracker.ERRORED,MediaTracker.COMPLETE 
 
-  
getImage
public Image getImage()
返回此图标的Image。- 结果
 -  
              
Image对象为ImageIcon 
 
-  
setImage
public void setImage(Image image)
设置此图标显示的图像。- 参数
 -  
              
image- 图像 
 
-  
getDescription
public String getDescription()
获取图像的描述。 这是对象的简短文本描述。 例如,可以将其呈现给盲人用户以指示图像的目的。 描述可能为空。- 结果
 - 图像的简短文字描述
 
 
-  
setDescription
public void setDescription(String description)
设置图像的描述。 这是对象的简短文本描述。 例如,可以将其呈现给盲人用户以指示图像的目的。- 参数
 -  
              
description- 图像的简短文字说明 
 
-  
paintIcon
public void paintIcon(Component c, Graphics g, int x, int y)
绘制图标。 图标的左上角的点(被绘制x,y在图形上下文的坐标空间)g。 如果此图标没有图像观察者,则此方法使用c组件作为观察者。 
-  
getIconWidth
public int getIconWidth()
获取图标的宽度。- Specified by:
 -  
              
getIconWidth在Icon - 结果
 - 此图标的宽度(以像素为单位)
 
 
-  
getIconHeight
public int getIconHeight()
获取图标的高度。- Specified by:
 -  
              
getIconHeight在接口Icon - 结果
 - 此图标的高度(以像素为单位)
 
 
-  
setImageObserver
public void setImageObserver(ImageObserver observer)
设置图像的图像观察者。 如果ImageIcon包含动画GIF,请设置此属性,以便通知观察者更新其显示。 例如:icon = new ImageIcon(...) button.setIcon(icon); icon.setImageObserver(button);- 参数
 -  
              
observer- 图像观察者 
 
-  
getImageObserver
public ImageObserver getImageObserver()
返回图像的图像观察者。- 结果
 - 图像观察者,可能为空
 
 
-  
getAccessibleContext
@BeanProperty(expert=true, description="The AccessibleContext associated with this ImageIcon.") public AccessibleContext getAccessibleContext()
获取与此ImageIcon关联的AccessibleContext。 对于图像图标,AccessibleContext采用AccessibleImageIcon的形式。 如有必要,将创建一个新的AccessibleImageIcon实例。- Specified by:
 -  
              
getAccessibleContext,接口Accessible - 结果
 - 一个AccessibleImageIcon,用作此ImageIcon的AccessibleContext
 - 从以下版本开始:
 - 1.3
 
 
 -  
 
 -