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 java.
.
Modifier and Type | Class and Description |
---|---|
protected class | ImageIcon.
This class implements accessibility support for the
|
Modifier and Type | Field and Description |
---|---|
private ImageIcon. | accessibleContext
--- Accessibility Support --- |
protected static final Component | component
Deprecated
since 1.8
Do not use this shared component, which is used to track image loading.
|
pack-priv String | |
private transient String | |
pack-priv int | |
pack-priv transient Image | |
pack-priv ImageObserver | |
pack-priv transient int | |
private transient URL | |
private static int | mediaTrackerID
Id used in loading images from MediaTracker. |
protected static final MediaTracker | tracker
Deprecated
since 1.8
Do not use this shared media tracker, which is used to load images.
|
private static final Object | |
pack-priv int |
Access | Constructor and Description |
---|---|
public | |
public | |
public | |
public | |
public | |
public | |
public | ImageIcon(byte[]
an array of pixels in an image format supported
by the AWT Toolkit, such as GIF, JPEG, or (as of 1.3) PNG imageData, String a brief textual description of the image 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. |
public | ImageIcon(byte[]
an array of pixels in an image format supported by
the AWT Toolkit, such as GIF, JPEG, or (as of 1.3) PNG 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. |
public |
Modifier and Type | Method and Description |
---|---|
private static Component | |
public AccessibleContext | Returns: an AccessibleImageIcon that serves as the AccessibleContext of this ImageIconImplements javax. |
public String | |
public int | Returns: the height in pixels of this iconImplements javax. |
public int | Returns: the width in pixels of this iconImplements javax. |
public Image | |
public int | Returns: the loading status as defined by java.awt.MediaTrackerReturns the status of the image loading operation. |
public ImageObserver | Returns: the image observer, which may be nullReturns the image observer for the image. |
private int | |
private MediaTracker | getTracker()
Returns the MediaTracker for the current AppContext, creating a new MediaTracker if necessary. |
protected void | |
public synchronized void | paintIcon(Component
the component to be used as the observer
if this icon has no image observer c, Graphics the graphics context g, int the X coordinate of the icon's top-left corner x, int the Y coordinate of the icon's top-left corner y)Implements javax. |
private void | |
public void | setDescription(String
a brief textual description of the image description)Sets the description of the image. |
public void | |
public void | |
public String | Returns: a string representing this imageOverrides java. |
private void |
accessibleContext | back to summary |
---|---|
private ImageIcon. --- Accessibility Support --- |
component | back to summary |
---|---|
protected static final Component component
Deprecated since 1.8 Do not use this shared component, which is used to track image loading. It is left for backward compatibility only.
|
description | back to summary |
---|---|
pack-priv String description |
filename | back to summary |
---|---|
private transient String filename |
height | back to summary |
---|---|
pack-priv int height |
image | back to summary |
---|---|
pack-priv transient Image image |
imageObserver | back to summary |
---|---|
pack-priv ImageObserver imageObserver |
loadStatus | back to summary |
---|---|
pack-priv transient int loadStatus |
location | back to summary |
---|---|
private transient URL location |
mediaTrackerID | back to summary |
---|---|
private static int mediaTrackerID Id used in loading images from MediaTracker. |
tracker | back to summary |
---|---|
protected static final MediaTracker tracker
Deprecated since 1.8 Do not use this shared media tracker, which is used to load images. It is left for backward compatibility only. |
TRACKER_KEY | back to summary |
---|---|
private static final Object TRACKER_KEY |
width | back to summary |
---|---|
pack-priv int width |
ImageIcon | back to summary |
---|---|
public ImageIcon(String filename, 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.
|
ImageIcon | back to summary |
---|---|
public ImageIcon(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. (The string is converted to an URL, so the forward-slash works on all systems.) For example, specify: new ImageIcon("images/myImage.gif")The description is initialized to the filename string.
|
ImageIcon | back to summary |
---|---|
public ImageIcon(URL location, 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.
|
ImageIcon | back to summary |
---|---|
public ImageIcon(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. The icon's description is initialized to be a string representation of the URL.
|
ImageIcon | back to summary |
---|---|
public ImageIcon(Image image, String description) Creates an ImageIcon from the image. |
ImageIcon | back to summary |
---|---|
public ImageIcon(Image image) Creates an ImageIcon from an image object. If the image has a "comment" property that is a string, then the string is used as the description of this icon.
|
ImageIcon | back to summary |
---|---|
public 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. Normally this array is created by reading an image using Class.getResourceAsStream(), but the byte array may also be statically stored in a class.
|
ImageIcon | back to summary |
---|---|
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, JPEG, or (as of 1.3) PNG. Normally this array is created by reading an image using Class.getResourceAsStream(), but the byte array may also be statically stored in a class. If the resulting image has a "comment" property that is a string, then the string is used as the description of this icon.
|
ImageIcon | back to summary |
---|---|
public ImageIcon() Creates an uninitialized image icon. |
createNoPermsComponent | back to summary |
---|---|
private static Component createNoPermsComponent()
|
getAccessibleContext | back to summary |
---|---|
public AccessibleContext getAccessibleContext() Implements javax. Gets the AccessibleContext associated with this ImageIcon. For image icons, the AccessibleContext takes the form of an AccessibleImageIcon. A new AccessibleImageIcon instance is created if necessary.
|
getDescription | back to summary |
---|---|
public String getDescription() Gets 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. The description may be null.
|
getIconHeight | back to summary |
---|---|
public int getIconHeight() Implements javax. Gets the height of the icon.
|
getIconWidth | back to summary |
---|---|
public int getIconWidth() Implements javax. Gets the width of the icon.
|
getImage | back to summary |
---|---|
public Image getImage() Returns this icon's
|
getImageLoadStatus | back to summary |
---|---|
public int getImageLoadStatus() Returns the status of the image loading operation.
|
getImageObserver | back to summary |
---|---|
public ImageObserver getImageObserver() Returns the image observer for the image.
|
getNextID | back to summary |
---|---|
private int getNextID() Returns an ID to use with the MediaTracker in loading an image. |
getTracker | back to summary |
---|---|
private MediaTracker getTracker() Returns the MediaTracker for the current AppContext, creating a new MediaTracker if necessary. |
loadImage | back to summary |
---|---|
protected void loadImage(Image image) Loads the image, returning only when the image is loaded.
|
paintIcon | back to summary |
---|---|
public synchronized void paintIcon(Component c, Graphics g, int x, int y) Implements javax. Paints the icon.
The top-left corner of the icon is drawn at
the point ( |
readObject | back to summary |
---|---|
private void readObject(ObjectInputStream s) throws ClassNotFoundException, IOException
|
setDescription | back to summary |
---|---|
public void setDescription(String description) Sets 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.
|
setImage | back to summary |
---|---|
public void setImage(Image image) Sets the image displayed by this icon.
|
setImageObserver | back to summary |
---|---|
public void setImageObserver(ImageObserver observer) Sets 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);
|
toString | back to summary |
---|---|
public String toString() Overrides java. Returns a string representation of this image.
|
writeObject | back to summary |
---|---|
private void writeObject(ObjectOutputStream s) throws IOException
|
ImageIcon
class. It provides an implementation of the
Java Accessibility API appropriate to image icon user-interface
elements.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 java.
.
Access | Constructor and Description |
---|---|
protected |
Modifier and Type | Method and Description |
---|---|
public Accessible | Returns: the nth Accessible child of the objectzero-based index of child i)Implements abstract javax. |
public int | Returns: the number of accessible children in the object.Implements abstract javax. |
public String | Returns: the description of the iconImplements javax. |
public int | Returns: the height of the iconImplements javax. |
public int | Returns: the width of the iconImplements javax. |
public int | Returns: the index of this object in its parent; -1 if this object does not have an accessible parent.Implements abstract javax. |
public Accessible | Returns: the Accessible parent of this object -- can be null if this object does not have an Accessible parentOverrides javax. |
public AccessibleRole | Returns: an instance of AccessibleRole describing the role of the objectImplements abstract javax. |
public AccessibleStateSet | Returns: an instance of AccessibleStateSet containing the current state set of the objectImplements abstract javax. |
public Locale | Returns: the locale of this objectImplements abstract javax. |
private void | |
public void | setAccessibleIconDescription(String
the description of the icon description)Implements javax. |
private void |
AccessibleImageIcon | back to summary |
---|---|
protected AccessibleImageIcon() Constructs an |
getAccessibleChild | back to summary |
---|---|
public Accessible getAccessibleChild(int i) Implements abstract javax. Returns the nth Accessible child of the object.
|
getAccessibleChildrenCount | back to summary |
---|---|
public int getAccessibleChildrenCount() Implements abstract javax. Returns the number of accessible children in the object. If all of the children of this object implement Accessible, than this method should return the number of children of this object.
|
getAccessibleIconDescription | back to summary |
---|---|
public String getAccessibleIconDescription() Implements javax. Gets the description of the icon. 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 icon.
|
getAccessibleIconHeight | back to summary |
---|---|
public int getAccessibleIconHeight() Implements javax. Gets the height of the icon.
|
getAccessibleIconWidth | back to summary |
---|---|
public int getAccessibleIconWidth() Implements javax. Gets the width of the icon.
|
getAccessibleIndexInParent | back to summary |
---|---|
public int getAccessibleIndexInParent() Implements abstract javax. Gets the index of this object in its accessible parent.
|
getAccessibleParent | back to summary |
---|---|
public Accessible getAccessibleParent() Overrides javax. Gets the Accessible parent of this object. If the parent of this object implements Accessible, this method should simply return getParent().
|
getAccessibleRole | back to summary |
---|---|
public AccessibleRole getAccessibleRole() Implements abstract javax. Gets the role of this object.
|
getAccessibleStateSet | back to summary |
---|---|
public AccessibleStateSet getAccessibleStateSet() Implements abstract javax. Gets the state of this object.
|
getLocale | back to summary |
---|---|
public Locale getLocale() throws IllegalComponentStateException Implements abstract javax. Returns the locale of this object.
|
readObject | back to summary |
---|---|
private void readObject(ObjectInputStream s) throws ClassNotFoundException, IOException
|
setAccessibleIconDescription | back to summary |
---|---|
public void setAccessibleIconDescription(String description) Implements javax. Sets the description of the icon. 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 icon.
|
writeObject | back to summary |
---|---|
private void writeObject(ObjectOutputStream s) throws IOException
|