Package com.kheops.ui.component
Class StretchIcon
java.lang.Object
javax.swing.ImageIcon
com.kheops.ui.component.StretchIcon
- All Implemented Interfaces:
Serializable
,Accessible
,Icon
An
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.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class javax.swing.ImageIcon
ImageIcon.AccessibleImageIcon
-
Field Summary
Modifier and TypeFieldDescriptionprotected boolean
Determines whether the aspect ratio of the image is maintained. -
Constructor Summary
ConstructorDescriptionStretchIcon
(byte[] imageData) Creates aStretchIcon
from an array of bytes.StretchIcon
(byte[] imageData, boolean proportionate) Creates aStretchIcon
from an array of bytes with the specified behavior.StretchIcon
(byte[] imageData, String description) Creates aStretchIcon
from an array of bytes.StretchIcon
(byte[] imageData, String description, boolean proportionate) Creates aStretchIcon
from an array of bytes with the specified behavior.StretchIcon
(Image image) Creates aStretchIcon
from the image.StretchIcon
(Image image, boolean proportionate) Creates aStretchIcon
from the image with the specified behavior.StretchIcon
(Image image, String description) Creates aStretchIcon
from the image.StretchIcon
(Image image, String description, boolean proportionate) Creates aStretchIcon
from the image with the specified behavior.StretchIcon
(String filename) Creates aStretchIcon
from the specified file.StretchIcon
(String filename, boolean proportionate) Creates aStretchIcon
from the specified file with the specified behavior.StretchIcon
(String filename, String description) Creates aStretchIcon
from the specified file.StretchIcon
(String filename, String description, boolean proportionate) Creates aStretchIcon
from the specified file with the specified behavior.StretchIcon
(URL location) Creates aStretchIcon
from the specified URL.StretchIcon
(URL location, boolean proportionate) Creates aStretchIcon
from the specified URL with the specified behavior.StretchIcon
(URL location, String description) Creates aStretchIcon
from the specified URL.StretchIcon
(URL location, String description, boolean proportionate) Creates aStretchIcon
from the specified URL with the specified behavior. -
Method Summary
Modifier and TypeMethodDescriptionint
Overridden to return 0.int
Overridden to return 0.void
Paints the icon.Methods inherited from class javax.swing.ImageIcon
getAccessibleContext, getDescription, getImage, getImageLoadStatus, getImageObserver, loadImage, setDescription, setImage, setImageObserver, toString
-
Field Details
-
proportionate
protected boolean proportionateDetermines whether the aspect ratio of the image is maintained. Set tofalse
to allow th image to distort to fill the component.
-
-
Constructor Details
-
StretchIcon
public StretchIcon(byte[] imageData) Creates aStretchIcon
from an array of bytes.- Parameters:
imageData
- an array of pixels in an image format supported by the AWT Toolkit, such as GIF, JPEG, or (as of 1.3) PNG- See Also:
-
StretchIcon
public StretchIcon(byte[] imageData, boolean proportionate) Creates aStretchIcon
from an array of bytes with the specified behavior.- Parameters:
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.- See Also:
-
StretchIcon
Creates aStretchIcon
from an array of bytes.- Parameters:
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 image- See Also:
-
StretchIcon
Creates aStretchIcon
from an array of bytes with the specified behavior.- Parameters:
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.- See Also:
-
StretchIcon
Creates aStretchIcon
from the image.- Parameters:
image
- the image- See Also:
-
StretchIcon
Creates aStretchIcon
from the image with the specified behavior.- Parameters:
image
- the imageproportionate
-true
to retain the image's aspect ratio,false
to allow distortion of the image to fill the component.- See Also:
-
StretchIcon
Creates aStretchIcon
from the image.- Parameters:
image
- the imagedescription
- a brief textual description of the image- See Also:
-
StretchIcon
Creates aStretchIcon
from the image with the specified behavior.- Parameters:
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.- See Also:
-
StretchIcon
Creates aStretchIcon
from the specified file.- Parameters:
filename
- a String specifying a filename or path- See Also:
-
StretchIcon
Creates aStretchIcon
from the specified file with the specified behavior.- Parameters:
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.- See Also:
-
StretchIcon
Creates aStretchIcon
from the specified file.- Parameters:
filename
- a String specifying a filename or pathdescription
- a brief textual description of the image- See Also:
-
StretchIcon
Creates aStretchIcon
from the specified file with the specified behavior.- Parameters:
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.- See Also:
-
StretchIcon
Creates aStretchIcon
from the specified URL.- Parameters:
location
- the URL for the image- See Also:
-
StretchIcon
Creates aStretchIcon
from the specified URL with the specified behavior.- Parameters:
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.- See Also:
-
StretchIcon
Creates aStretchIcon
from the specified URL.- Parameters:
location
- the URL for the imagedescription
- a brief textual description of the image- See Also:
-
StretchIcon
Creates aStretchIcon
from the specified URL with the specified behavior.- Parameters:
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.- See Also:
-
-
Method Details
-
paintIcon
Paints the icon. The image is reduced or magnified to fit the component to which it is painted.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. -
getIconWidth
public int getIconWidth()Overridden to return 0. The size of this Icon is determined by the size of the component.- Specified by:
getIconWidth
in interfaceIcon
- Overrides:
getIconWidth
in classImageIcon
- Returns:
- 0
-
getIconHeight
public int getIconHeight()Overridden to return 0. The size of this Icon is determined by the size of the component.- Specified by:
getIconHeight
in interfaceIcon
- Overrides:
getIconHeight
in classImageIcon
- Returns:
- 0
-