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
FieldsModifier and TypeFieldDescriptionprotected booleanDetermines whether the aspect ratio of the image is maintained. -
Constructor Summary
ConstructorsConstructorDescriptionStretchIcon(byte[] imageData) Creates aStretchIconfrom an array of bytes.StretchIcon(byte[] imageData, boolean proportionate) Creates aStretchIconfrom an array of bytes with the specified behavior.StretchIcon(byte[] imageData, String description) Creates aStretchIconfrom an array of bytes.StretchIcon(byte[] imageData, String description, boolean proportionate) Creates aStretchIconfrom an array of bytes with the specified behavior.StretchIcon(Image image) Creates aStretchIconfrom the image.StretchIcon(Image image, boolean proportionate) Creates aStretchIconfrom the image with the specified behavior.StretchIcon(Image image, String description) Creates aStretchIconfrom the image.StretchIcon(Image image, String description, boolean proportionate) Creates aStretchIconfrom the image with the specified behavior.StretchIcon(String filename) Creates aStretchIconfrom the specified file.StretchIcon(String filename, boolean proportionate) Creates aStretchIconfrom the specified file with the specified behavior.StretchIcon(String filename, String description) Creates aStretchIconfrom the specified file.StretchIcon(String filename, String description, boolean proportionate) Creates aStretchIconfrom the specified file with the specified behavior.StretchIcon(URL location) Creates aStretchIconfrom the specified URL.StretchIcon(URL location, boolean proportionate) Creates aStretchIconfrom the specified URL with the specified behavior.StretchIcon(URL location, String description) Creates aStretchIconfrom the specified URL.StretchIcon(URL location, String description, boolean proportionate) Creates aStretchIconfrom the specified URL with the specified behavior. -
Method Summary
Modifier and TypeMethodDescriptionintOverridden to return 0.intOverridden to return 0.voidPaints 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 tofalseto allow th image to distort to fill the component.
-
-
Constructor Details
-
StretchIcon
public StretchIcon(byte[] imageData) Creates aStretchIconfrom 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 aStretchIconfrom 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-trueto retain the image's aspect ratio,falseto allow distortion of the image to fill the component.- See Also:
-
StretchIcon
Creates aStretchIconfrom 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 aStretchIconfrom 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-trueto retain the image's aspect ratio,falseto allow distortion of the image to fill the component.- See Also:
-
StretchIcon
Creates aStretchIconfrom the image.- Parameters:
image- the image- See Also:
-
StretchIcon
Creates aStretchIconfrom the image with the specified behavior.- Parameters:
image- the imageproportionate-trueto retain the image's aspect ratio,falseto allow distortion of the image to fill the component.- See Also:
-
StretchIcon
Creates aStretchIconfrom the image.- Parameters:
image- the imagedescription- a brief textual description of the image- See Also:
-
StretchIcon
Creates aStretchIconfrom the image with the specified behavior.- Parameters:
image- the imagedescription- a brief textual description of the imageproportionate-trueto retain the image's aspect ratio,falseto allow distortion of the image to fill the component.- See Also:
-
StretchIcon
Creates aStretchIconfrom the specified file.- Parameters:
filename- a String specifying a filename or path- See Also:
-
StretchIcon
Creates aStretchIconfrom the specified file with the specified behavior.- Parameters:
filename- a String specifying a filename or pathproportionate-trueto retain the image's aspect ratio,falseto allow distortion of the image to fill the component.- See Also:
-
StretchIcon
Creates aStretchIconfrom the specified file.- Parameters:
filename- a String specifying a filename or pathdescription- a brief textual description of the image- See Also:
-
StretchIcon
Creates aStretchIconfrom the specified file with the specified behavior.- Parameters:
filename- a String specifying a filename or pathdescription- a brief textual description of the imageproportionate-trueto retain the image's aspect ratio,falseto allow distortion of the image to fill the component.- See Also:
-
StretchIcon
Creates aStretchIconfrom the specified URL.- Parameters:
location- the URL for the image- See Also:
-
StretchIcon
Creates aStretchIconfrom the specified URL with the specified behavior.- Parameters:
location- the URL for the imageproportionate-trueto retain the image's aspect ratio,falseto allow distortion of the image to fill the component.- See Also:
-
StretchIcon
Creates aStretchIconfrom the specified URL.- Parameters:
location- the URL for the imagedescription- a brief textual description of the image- See Also:
-
StretchIcon
Creates aStretchIconfrom the specified URL with the specified behavior.- Parameters:
location- the URL for the imagedescription- a brief textual description of the imageproportionate-trueto retain the image's aspect ratio,falseto 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
ccomponent 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:
getIconWidthin interfaceIcon- Overrides:
getIconWidthin 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:
getIconHeightin interfaceIcon- Overrides:
getIconHeightin classImageIcon- Returns:
- 0
-