Class StretchIcon

java.lang.Object
javax.swing.ImageIcon
com.kheops.ui.component.StretchIcon
All Implemented Interfaces:
Serializable, Accessible, Icon

public class StretchIcon extends ImageIcon
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:
  • Field Details

    • proportionate

      protected boolean proportionate
      Determines whether the aspect ratio of the image is maintained. Set to false to allow th image to distort to fill the component.
  • Constructor Details

    • StretchIcon

      public StretchIcon(byte[] imageData)
      Creates a StretchIcon 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 a StretchIcon 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) PNG
      proportionate - true to retain the image's aspect ratio, false to allow distortion of the image to fill the component.
      See Also:
    • StretchIcon

      public StretchIcon(byte[] imageData, String description)
      Creates a StretchIcon 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
      description - a brief textual description of the image
      See Also:
    • StretchIcon

      public StretchIcon(byte[] imageData, String description, boolean proportionate)
      Creates a StretchIcon 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) PNG
      description - a brief textual description of the image
      proportionate - true to retain the image's aspect ratio, false to allow distortion of the image to fill the component.
      See Also:
    • StretchIcon

      public StretchIcon(Image image)
      Creates a StretchIcon from the image.
      Parameters:
      image - the image
      See Also:
    • StretchIcon

      public StretchIcon(Image image, boolean proportionate)
      Creates a StretchIcon from the image with the specified behavior.
      Parameters:
      image - the image
      proportionate - true to retain the image's aspect ratio, false to allow distortion of the image to fill the component.
      See Also:
    • StretchIcon

      public StretchIcon(Image image, String description)
      Creates a StretchIcon from the image.
      Parameters:
      image - the image
      description - a brief textual description of the image
      See Also:
    • StretchIcon

      public StretchIcon(Image image, String description, boolean proportionate)
      Creates a StretchIcon from the image with the specified behavior.
      Parameters:
      image - the image
      description - a brief textual description of the image
      proportionate - true to retain the image's aspect ratio, false to allow distortion of the image to fill the component.
      See Also:
    • StretchIcon

      public StretchIcon(String filename)
      Creates a StretchIcon from the specified file.
      Parameters:
      filename - a String specifying a filename or path
      See Also:
    • StretchIcon

      public StretchIcon(String filename, boolean proportionate)
      Creates a StretchIcon from the specified file with the specified behavior.
      Parameters:
      filename - a String specifying a filename or path
      proportionate - true to retain the image's aspect ratio, false to allow distortion of the image to fill the component.
      See Also:
    • StretchIcon

      public StretchIcon(String filename, String description)
      Creates a StretchIcon from the specified file.
      Parameters:
      filename - a String specifying a filename or path
      description - a brief textual description of the image
      See Also:
    • StretchIcon

      public StretchIcon(String filename, String description, boolean proportionate)
      Creates a StretchIcon from the specified file with the specified behavior.
      Parameters:
      filename - a String specifying a filename or path
      description - a brief textual description of the image
      proportionate - true to retain the image's aspect ratio, false to allow distortion of the image to fill the component.
      See Also:
    • StretchIcon

      public StretchIcon(URL location)
      Creates a StretchIcon from the specified URL.
      Parameters:
      location - the URL for the image
      See Also:
    • StretchIcon

      public StretchIcon(URL location, boolean proportionate)
      Creates a StretchIcon from the specified URL with the specified behavior.
      Parameters:
      location - the URL for the image
      proportionate - true to retain the image's aspect ratio, false to allow distortion of the image to fill the component.
      See Also:
    • StretchIcon

      public StretchIcon(URL location, String description)
      Creates a StretchIcon from the specified URL.
      Parameters:
      location - the URL for the image
      description - a brief textual description of the image
      See Also:
    • StretchIcon

      public StretchIcon(URL location, String description, boolean proportionate)
      Creates a StretchIcon from the specified URL with the specified behavior.
      Parameters:
      location - the URL for the image
      description - a brief textual description of the image
      proportionate - true to retain the image's aspect ratio, false to allow distortion of the image to fill the component.
      See Also:
  • Method Details

    • paintIcon

      public void paintIcon(Component c, Graphics g, int x, int y)
      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.

      Specified by:
      paintIcon in interface Icon
      Overrides:
      paintIcon in class ImageIcon
      Parameters:
      c - the component to which the Icon is painted. This is used as the observer if this icon has no image observer
      g - the graphics context
      x - not used.
      y - not used.
      See Also:
    • 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 interface Icon
      Overrides:
      getIconWidth in class ImageIcon
      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 interface Icon
      Overrides:
      getIconHeight in class ImageIcon
      Returns:
      0