Class ThemedSingleImageIcon

  • All Implemented Interfaces:
    ThemedIcon, javax.swing.Icon

    public final class ThemedSingleImageIcon
    extends AbstractThemedIcon
    An image icon that scales the source image appropriately for high DPI displays. This is a simpler alternative to ThemedImageIcon that is preferable when it is known that only one source image is available. Where a ThemedImageIcon chooses an image from one or more possible representations, this class will cache a high-quality pre-scaled image adjusted for the desktop scale.
    Since:
    3.4
    Author:
    Chris Jennings
    • Constructor Detail

      • ThemedSingleImageIcon

        public ThemedSingleImageIcon​(java.lang.String imageResource)
        Creates a new, small icon from the specified image resource identifier.
        Parameters:
        imageResource - the non-null image resource, e.g., "res://path/image.png"
      • ThemedSingleImageIcon

        public ThemedSingleImageIcon​(java.lang.String imageResource,
                                     int size)
        Creates a new icon from the specified image resource identifier. This is a cover for creating an icon of equal width and height.
        Parameters:
        imageResource - the non-null image resource, e.g., "res://path/image.png"
        size - the desired icon width and height
      • ThemedSingleImageIcon

        public ThemedSingleImageIcon​(java.lang.String imageResource,
                                     int iconWidth,
                                     int iconHeight)
        Creates a new icon from the specified image resource identifier. The width and height should be given as if the desktop is not being scaled.
        Parameters:
        imageResource - the non-null image resource, e.g., "res://path/image.png"
        iconWidth - the desired icon width
        iconHeight - the desired icon height
      • ThemedSingleImageIcon

        public ThemedSingleImageIcon​(java.awt.image.BufferedImage sourceImage)
        Creates a new, small icon from the specified image.
        Parameters:
        sourceImage - the non-null image
      • ThemedSingleImageIcon

        public ThemedSingleImageIcon​(java.awt.image.BufferedImage sourceImage,
                                     int size)
        Creates a new icon from the specified image. This is a cover for creating an icon of equal width and height.
        Parameters:
        sourceImage - the non-null image
        size - the desired icon width and height
      • ThemedSingleImageIcon

        public ThemedSingleImageIcon​(java.awt.image.BufferedImage sourceImage,
                                     int iconWidth,
                                     int iconHeight)
        Creates a new icon from the specified image. The width and height should be given as if the desktop is not being scaled.
        Parameters:
        sourceImage - the non-null image
        iconWidth - the desired icon width
        iconHeight - the desired icon height
    • Method Detail

      • getResource

        public java.lang.String getResource()
        Returns the resource identifier for this icon. This will be null if the icon was not created from a resource identifier.
        Returns:
        the image resource
      • getImage

        public java.awt.image.BufferedImage getImage()
        Returns the source image that this icon will use as a basis for drawing.
        Returns:
        the non-null source image
      • paintIcon

        protected void paintIcon​(java.awt.Component c,
                                 java.awt.Graphics2D g,
                                 int x,
                                 int y)
        Specified by:
        paintIcon in class AbstractThemedIcon
      • derive

        public ThemedIcon derive​(int newWidth,
                                 int newHeight)
        Description copied from interface: ThemedIcon
        Returns a new icon that renders the same image as this icon, but at a different size.
        Parameters:
        newWidth - the new width ≥ 1
        newHeight - the new height ≥ 1
        Returns:
        an icon with the revised dimensions