Class ThemedImageIcon

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

    public class ThemedImageIcon
    extends AbstractThemedIcon
    An icon that whose image can change according to the installed Theme. Supports multi-resolution images using file name suffixes (such as myicon@2x.png).
    Since:
    3.4
    Author:
    Chris Jennings
    • Constructor Detail

      • ThemedImageIcon

        public ThemedImageIcon​(java.lang.String resource)
        Creates a new themed icon from an image resource.
        Parameters:
        resource - the non-null image resource, e.g., "res://path/image.png"
      • ThemedImageIcon

        public ThemedImageIcon​(java.lang.String resource,
                               boolean deferLoading)
        Creates a new themed icon from an image resource. If deferLoading is true, then it will not be loaded until the first time it is used. Otherwise, the image may start loading immediately in a background thread.
        Parameters:
        resource - the the non-null image resource, e.g., "res://path/image.png"
        deferLoading - if true, the image is loaded lazily
        See Also:
        Theme#applyThemeToImage(java.lang.String)
      • ThemedImageIcon

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

        public ThemedImageIcon​(java.lang.String resource,
                               int iconWidth,
                               int iconHeight)
        Creates a new themed icon with the specified size.
        Parameters:
        resource - the the non-null image resource, e.g., "res://path/image.png"
        iconWidth - the desired icon width (for 1:1 displays)
        iconHeight - the desired icon height (for 1:1 displays)
      • ThemedImageIcon

        public ThemedImageIcon​(java.awt.image.MultiResolutionImage image,
                               int width,
                               int height)
        Creates a themed icon from a multiresolution image source.
        Parameters:
        image - the non-null image to use as a base for the icon
        width - the icon width
        height - the icon height
      • ThemedImageIcon

        public ThemedImageIcon​(java.awt.image.BufferedImage... images)
        Creates a new themed icon directly from one or images. Each image should be a different version of the same graphic, but scaled for a different size or resolution. The initial size of the icon will be taken from the size of the first image; this can be changed by calling derive(int,int).

        If only one source image is available, it is recommended to use ThemedSingleImageIcon instead, as this will generally produce a higher quality image.

        Parameters:
        images - a non-null array of at least one image
    • 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
      • getMultiResolutionImage

        public final java.awt.image.AbstractMultiResolutionImage getMultiResolutionImage()
        Returns an image that can be used to render the icon's image at multiple resolutions.
        Returns:
        a multi-resolution version of the source image
      • derive

        public final ThemedImageIcon derive​(int newWidth,
                                            int newHeight)
        Returns an icon with the same base image as this icon, but which renders with a different nominal size or state.
        Parameters:
        newWidth - the new width (on 1:1 displays)
        newHeight - the new height (on 1:1 displays)
        Returns:
        an icon for the new size
      • disabled

        public final ThemedImageIcon disabled()
        Description copied from interface: ThemedIcon
        Returns a new icon that renders the same image as this icon, but as if for a permanently disabled component.
        Specified by:
        disabled in interface ThemedIcon
        Overrides:
        disabled in class AbstractThemedIcon
        Returns:
        a disabled verison of the icon
      • getIconWidth

        public int getIconWidth()
        Specified by:
        getIconWidth in interface javax.swing.Icon
        Overrides:
        getIconWidth in class AbstractThemedIcon
      • getIconHeight

        public int getIconHeight()
        Specified by:
        getIconHeight in interface javax.swing.Icon
        Overrides:
        getIconHeight in class AbstractThemedIcon
      • paintIcon

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