Class FlatSVGIcon

  • All Implemented Interfaces:
    com.formdev.flatlaf.FlatLaf.DisabledIconProvider, java.io.Serializable, javax.accessibility.Accessible, javax.swing.Icon

    public class FlatSVGIcon
    extends javax.swing.ImageIcon
    implements com.formdev.flatlaf.FlatLaf.DisabledIconProvider
    An icon that loads and paints SVG.
    See Also:
    Serialized Form
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  FlatSVGIcon.ColorFilter  
      • Nested classes/interfaces inherited from class javax.swing.ImageIcon

        javax.swing.ImageIcon.AccessibleImageIcon
    • Field Summary

      • Fields inherited from class javax.swing.ImageIcon

        component, tracker
    • Constructor Summary

      Constructors 
      Constructor Description
      FlatSVGIcon​(java.lang.String name)
      Creates an SVG icon from the given resource name.
      FlatSVGIcon​(java.lang.String name, float scale)
      Creates an SVG icon from the given resource name that is scaled by the given amount.
      FlatSVGIcon​(java.lang.String name, float scale, java.lang.ClassLoader classLoader)
      Creates an SVG icon from the given resource name that is scaled by the given amount.
      FlatSVGIcon​(java.lang.String name, int width, int height)
      Creates an SVG icon from the given resource name with the given width and height.
      FlatSVGIcon​(java.lang.String name, int width, int height, java.lang.ClassLoader classLoader)
      Creates an SVG icon from the given resource name with the given width and height.
      FlatSVGIcon​(java.lang.String name, java.lang.ClassLoader classLoader)
      Creates an SVG icon from the given resource name.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      FlatSVGIcon derive​(float scale)
      Creates a new icon with given scaling, which is derived from this icon.
      FlatSVGIcon derive​(int width, int height)
      Creates a new icon with given width and height, which is derived from this icon.
      javax.swing.Icon getDisabledIcon()
      Creates a new icon with disabled appearance, which is derived from this icon.
      int getIconHeight()
      Returns the scaled height of the icon.
      int getIconWidth()
      Returns the scaled width of the icon.
      java.awt.Image getImage()  
      boolean hasFound()
      Returns whether the SVG file was found.
      void paintIcon​(java.awt.Component c, java.awt.Graphics g, int x, int y)  
      • Methods inherited from class javax.swing.ImageIcon

        getAccessibleContext, getDescription, getImageLoadStatus, getImageObserver, loadImage, setDescription, setImage, setImageObserver, toString
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • FlatSVGIcon

        public FlatSVGIcon​(java.lang.String name)
        Creates an SVG icon from the given resource name.

        The SVG attributes width and height (or viewBox) in the tag <svg> are used as icon size.

        Parameters:
        name - the name of the SVG resource (a '/'-separated path)
        See Also:
        ClassLoader.getResource(String)
      • FlatSVGIcon

        public FlatSVGIcon​(java.lang.String name,
                           java.lang.ClassLoader classLoader)
        Creates an SVG icon from the given resource name. The SVG file is loaded from the given class loader.

        The SVG attributes width and height (or viewBox) in the tag <svg> are used as icon size.

        Parameters:
        name - the name of the SVG resource (a '/'-separated path)
        classLoader - the class loader used to load the SVG resource
        See Also:
        ClassLoader.getResource(String)
      • FlatSVGIcon

        public FlatSVGIcon​(java.lang.String name,
                           int width,
                           int height)
        Creates an SVG icon from the given resource name with the given width and height.

        The icon is scaled if the given size is different to the size specified in the SVG file.

        Parameters:
        name - the name of the SVG resource (a '/'-separated path)
        width - the width of the icon
        height - the height of the icon
        See Also:
        ClassLoader.getResource(String)
      • FlatSVGIcon

        public FlatSVGIcon​(java.lang.String name,
                           int width,
                           int height,
                           java.lang.ClassLoader classLoader)
        Creates an SVG icon from the given resource name with the given width and height. The SVG file is loaded from the given class loader.

        The icon is scaled if the given size is different to the size specified in the SVG file.

        Parameters:
        name - the name of the SVG resource (a '/'-separated path)
        width - the width of the icon
        height - the height of the icon
        classLoader - the class loader used to load the SVG resource
        See Also:
        ClassLoader.getResource(String)
      • FlatSVGIcon

        public FlatSVGIcon​(java.lang.String name,
                           float scale)
        Creates an SVG icon from the given resource name that is scaled by the given amount.

        The SVG attributes width and height (or viewBox) in the tag <svg> are used as base icon size, which is multiplied by the given scale factor.

        Parameters:
        name - the name of the SVG resource (a '/'-separated path)
        scale - the amount by which the icon size is scaled
        See Also:
        ClassLoader.getResource(String)
      • FlatSVGIcon

        public FlatSVGIcon​(java.lang.String name,
                           float scale,
                           java.lang.ClassLoader classLoader)
        Creates an SVG icon from the given resource name that is scaled by the given amount. The SVG file is loaded from the given class loader.

        The SVG attributes width and height (or viewBox) in the tag <svg> are used as base icon size, which is multiplied by the given scale factor.

        Parameters:
        name - the name of the SVG resource (a '/'-separated path)
        scale - the amount by which the icon size is scaled
        classLoader - the class loader used to load the SVG resource
        See Also:
        ClassLoader.getResource(String)
    • Method Detail

      • derive

        public FlatSVGIcon derive​(int width,
                                  int height)
        Creates a new icon with given width and height, which is derived from this icon.
        Parameters:
        width - the width of the new icon
        height - the height of the new icon
        Returns:
        a new icon
      • derive

        public FlatSVGIcon derive​(float scale)
        Creates a new icon with given scaling, which is derived from this icon.
        Parameters:
        scale - the amount by which the icon size is scaled
        Returns:
        a new icon
      • getDisabledIcon

        public javax.swing.Icon getDisabledIcon()
        Creates a new icon with disabled appearance, which is derived from this icon.
        Specified by:
        getDisabledIcon in interface com.formdev.flatlaf.FlatLaf.DisabledIconProvider
        Returns:
        a new icon
      • hasFound

        public boolean hasFound()
        Returns whether the SVG file was found.
        Returns:
        whether the SVG file was found
      • getIconWidth

        public int getIconWidth()
        Returns the scaled width of the icon.
        Specified by:
        getIconWidth in interface javax.swing.Icon
        Overrides:
        getIconWidth in class javax.swing.ImageIcon
      • getIconHeight

        public int getIconHeight()
        Returns the scaled height of the icon.
        Specified by:
        getIconHeight in interface javax.swing.Icon
        Overrides:
        getIconHeight in class javax.swing.ImageIcon
      • paintIcon

        public void paintIcon​(java.awt.Component c,
                              java.awt.Graphics g,
                              int x,
                              int y)
        Specified by:
        paintIcon in interface javax.swing.Icon
        Overrides:
        paintIcon in class javax.swing.ImageIcon
      • getImage

        public java.awt.Image getImage()
        Overrides:
        getImage in class javax.swing.ImageIcon