Contents

Swinging Duke
Feedback Button
Left ArrowRight Arrow

 

Little Pictures in Swing Components

To handle icons -- the Swing term for just about any small graphics image -- Swing provides a class named ImageIcon. The ImageIcon class extends the Object class and implements an interface named Icon.

Objects instantiated from the ImageIcon class paint icons from Images. Images that are created from a URL or filename are preloaded using MediaTracker to monitor the loaded state of the image.


The Icon Interface

The Icon interface implements three methods:

getIconHeight()
getIconWidth()
paintIcon(Component c, Graphics, int, int)


The ImageIcon API

The ImageIcon API defines the following methods:

getIconHeight()

Gets the height of a icons.

setImage()

Sets the icon's image.

getImage()

Returns a icon's image.

getIconWidth()

Gets the width of a icons.

loadImage(Image)

Waits for an image to load.

paintIcon(Component c, Graphics, int, int)

Paints a icons.

Comprehensive documentation for the ImageIcon class and the Icon interface is still under development. Meanwhile, refer to the applicable JavaDoc APIs for current information.


Version 0.5. Last modified 10/4/97.
Copyright © 1995-97 Sun Microsystems, Inc. All Rights Reserved.

Sun's Home Page