Class ScalableImageIcon

  • All Implemented Interfaces:
    ResizableIcon, java.io.Serializable, java.lang.Cloneable, javax.accessibility.Accessible, javax.swing.Icon
    Direct Known Subclasses:
    DoubleSizeImageIcon, ResizableIconImageIcon

    @OpenApiAll
    public class ScalableImageIcon
    extends javax.swing.ImageIcon
    implements ResizableIcon
    HiDPI(Retina) friendly ImageIcon implementation.

    This class dynamically chooses a right image by current screen dpi and/or scaling factor defined in the system (Retina and etc). If scaling is needed and svg icon with the same name is available at given location, svg icon will be used instead of a bitmap icon.

    Dynamic choosing will work only if two icons are provided at the same location. For example:

  • /com/product/icons/a.png
  • /com/product/icons/a.svg
  • ScalableImageIcon(Product.class, "/com/product/icons/a.png") will load a.png on a regular dpi monitor, but a.svg will be loaded on HiDPI monitor. Keep in mind that svg icon size can be any. Svg icon will be re-sized according to the size of a.png icon and scaling factor. For example if size of a.png is 16x16 and scaling factor is 2, loaded svg icon will be re-sized to 32x32 if needed.

    Original icon will be loaded and scaled if svg icon is not provided, but HiDPI with scaling is used.

    Icon image loading is lazy. Image will be loaded only if icon is painted, getImage() is called or icon width/height is retrieved.

See Also:
Serialized Form