public class StretchIcon
extends javax.swing.ImageIcon
Icon that scales its image to fill the component area,
excluding any border or insets, optionally maintaining the image's aspect
ratio by padding and centering the scaled image horizontally or vertically.
The class is a drop-in replacement for ImageIcon, except that
the no-argument constructor is not supported.
As the size of the Icon is determined by the size of the component in which
it is displayed, StretchIcon must only be used in conjunction
with a component and layout that does not depend on the size of the
component's Icon.
| Modifier and Type | Field and Description |
|---|---|
protected boolean |
proportionate
Determines whether the aspect ratio of the image is maintained.
|
| Constructor and Description |
|---|
StretchIcon(byte[] imageData)
Creates a
StretchIcon from an array of bytes. |
StretchIcon(byte[] imageData,
boolean proportionate)
Creates a
StretchIcon from an array of bytes with the
specified behavior. |
StretchIcon(byte[] imageData,
java.lang.String description)
Creates a
StretchIcon from an array of bytes. |
StretchIcon(byte[] imageData,
java.lang.String description,
boolean proportionate)
Creates a
StretchIcon from an array of bytes with the
specified behavior. |
StretchIcon(java.awt.Image image)
Creates a
StretchIcon from the image. |
StretchIcon(java.awt.Image image,
boolean proportionate)
Creates a
StretchIcon from the image with the specified
behavior. |
StretchIcon(java.awt.Image image,
java.lang.String description)
Creates a
StretchIcon from the image. |
StretchIcon(java.awt.Image image,
java.lang.String description,
boolean proportionate)
Creates a
StretchIcon from the image with the specified
behavior. |
StretchIcon(java.lang.String filename)
Creates a
StretchIcon from the specified file. |
StretchIcon(java.lang.String filename,
boolean proportionate)
Creates a
StretchIcon from the specified file with the
specified behavior. |
StretchIcon(java.lang.String filename,
java.lang.String description)
Creates a
StretchIcon from the specified file. |
StretchIcon(java.lang.String filename,
java.lang.String description,
boolean proportionate)
Creates a
StretchIcon from the specified file with the
specified behavior. |
StretchIcon(java.net.URL location)
Creates a
StretchIcon from the specified URL. |
StretchIcon(java.net.URL location,
boolean proportionate)
Creates a
StretchIcon from the specified URL with the
specified behavior. |
StretchIcon(java.net.URL location,
java.lang.String description)
Creates a
StretchIcon from the specified URL. |
StretchIcon(java.net.URL location,
java.lang.String description,
boolean proportionate)
Creates a
StretchIcon from the specified URL with the
specified behavior. |
| Modifier and Type | Method and Description |
|---|---|
int |
getIconHeight()
Overridden to return 0.
|
int |
getIconWidth()
Overridden to return 0.
|
void |
paintIcon(java.awt.Component c,
java.awt.Graphics g,
int x,
int y)
Paints the icon.
|
protected boolean proportionate
false to allow th image to distort to fill the component.public StretchIcon(byte[] imageData)
StretchIcon from an array of bytes.imageData - an array of pixels in an image format supported by the AWT
Toolkit, such as GIF, JPEG, or (as of 1.3) PNGImageIcon.ImageIcon(byte[])public StretchIcon(byte[] imageData,
boolean proportionate)
StretchIcon from an array of bytes with the
specified behavior.imageData - an array of pixels in an image format supported by the AWT
Toolkit, such as GIF, JPEG, or (as of 1.3) PNGproportionate - true to retain the image's aspect ratio,
false to allow distortion of the image to fill the
component.ImageIcon.ImageIcon(byte[])public StretchIcon(byte[] imageData,
java.lang.String description)
StretchIcon from an array of bytes.imageData - an array of pixels in an image format supported by the AWT
Toolkit, such as GIF, JPEG, or (as of 1.3) PNGdescription - a brief textual description of the imageImageIcon.ImageIcon(byte[], java.lang.String)public StretchIcon(byte[] imageData,
java.lang.String description,
boolean proportionate)
StretchIcon from an array of bytes with the
specified behavior.imageData - an array of pixels in an image format supported by the AWT
Toolkit, such as GIF, JPEG, or (as of 1.3) PNGdescription - a brief textual description of the imageproportionate - true to retain the image's aspect ratio,
false to allow distortion of the image to fill the
component.ImageIcon.ImageIcon(byte[]),
ImageIcon.ImageIcon(byte[], java.lang.String)public StretchIcon(java.awt.Image image)
StretchIcon from the image.image - the imageImageIcon.ImageIcon(java.awt.Image)public StretchIcon(java.awt.Image image,
boolean proportionate)
StretchIcon from the image with the specified
behavior.image - the imageproportionate - true to retain the image's aspect ratio,
false to allow distortion of the image to fill the
component.ImageIcon.ImageIcon(java.awt.Image)public StretchIcon(java.awt.Image image,
java.lang.String description)
StretchIcon from the image.image - the imagedescription - a brief textual description of the imageImageIcon.ImageIcon(java.awt.Image, java.lang.String)public StretchIcon(java.awt.Image image,
java.lang.String description,
boolean proportionate)
StretchIcon from the image with the specified
behavior.image - the imagedescription - a brief textual description of the imageproportionate - true to retain the image's aspect ratio,
false to allow distortion of the image to fill the
component.ImageIcon.ImageIcon(java.awt.Image, java.lang.String)public StretchIcon(java.lang.String filename)
StretchIcon from the specified file.filename - a String specifying a filename or pathImageIcon.ImageIcon(java.lang.String)public StretchIcon(java.lang.String filename,
boolean proportionate)
StretchIcon from the specified file with the
specified behavior.filename - a String specifying a filename or pathproportionate - true to retain the image's aspect ratio,
false to allow distortion of the image to fill the
component.ImageIcon.ImageIcon(java.lang.String)public StretchIcon(java.lang.String filename,
java.lang.String description)
StretchIcon from the specified file.filename - a String specifying a filename or pathdescription - a brief textual description of the imageImageIcon.ImageIcon(java.lang.String, java.lang.String)public StretchIcon(java.lang.String filename,
java.lang.String description,
boolean proportionate)
StretchIcon from the specified file with the
specified behavior.filename - a String specifying a filename or pathdescription - a brief textual description of the imageproportionate - true to retain the image's aspect ratio,
false to allow distortion of the image to fill the
component.ImageIcon.ImageIcon(java.awt.Image, java.lang.String)public StretchIcon(java.net.URL location)
StretchIcon from the specified URL.location - the URL for the imageImageIcon.ImageIcon(java.net.URL)public StretchIcon(java.net.URL location,
boolean proportionate)
StretchIcon from the specified URL with the
specified behavior.location - the URL for the imageproportionate - true to retain the image's aspect ratio,
false to allow distortion of the image to fill the
component.ImageIcon.ImageIcon(java.net.URL)public StretchIcon(java.net.URL location,
java.lang.String description)
StretchIcon from the specified URL.location - the URL for the imagedescription - a brief textual description of the imageImageIcon.ImageIcon(java.net.URL, java.lang.String)public StretchIcon(java.net.URL location,
java.lang.String description,
boolean proportionate)
StretchIcon from the specified URL with the
specified behavior.location - the URL for the imagedescription - a brief textual description of the imageproportionate - true to retain the image's aspect ratio,
false to allow distortion of the image to fill the
component.ImageIcon.ImageIcon(java.net.URL, java.lang.String)public void paintIcon(java.awt.Component c,
java.awt.Graphics g,
int x,
int y)
If the proportion has not been specified, or has been specified as
true, the aspect ratio of the image will be preserved by
padding and centering the image horizontally or vertically. Otherwise the
image may be distorted to fill the component it is painted to.
If this icon has no image observer,this method uses the c
component as the observer.
paintIcon in interface javax.swing.IconpaintIcon in class javax.swing.ImageIconc - the component to which the Icon is painted. This is used as the
observer if this icon has no image observerg - the graphics contextx - not used.y - not used.ImageIcon.paintIcon(java.awt.Component, java.awt.Graphics, int, int)public int getIconWidth()
getIconWidth in interface javax.swing.IcongetIconWidth in class javax.swing.ImageIconpublic int getIconHeight()
getIconHeight in interface javax.swing.IcongetIconHeight in class javax.swing.ImageIcon