Class FlatSVGUtils

java.lang.Object
com.formdev.flatlaf.extras.FlatSVGUtils

public class FlatSVGUtils extends Object
Utility methods for SVG.
  • Constructor Details

    • FlatSVGUtils

      public FlatSVGUtils()
  • Method Details

    • createWindowIconImages

      public static List<Image> createWindowIconImages(String svgName)
      Creates from the given SVG a list of icon images with different sizes that can be used for windows headers. The SVG should have a size of 16x16, otherwise it is scaled.

      If running on Windows in Java 9 or later and multi-resolution image support is available, then a single multi-resolution image is returned that creates images on demand for requested sizes from SVG. This has the advantage that only images for used sizes are created. Also, if unusual sizes are requested (e.g. 18x18), then they are created from SVG.

      If using Java modules, the package containing the SVG must be opened in module-info.java. Otherwise, use createWindowIconImages(URL).

      Parameters:
      svgName - the name of the SVG resource (a '/'-separated path)
      Returns:
      list of icon images with different sizes (16x16, 20x20, 24x24, 28x28, 32x32, 48x48 and 64x64)
      Throws:
      RuntimeException - if failed to load or render SVG file
      See Also:
    • createWindowIconImages

      public static List<Image> createWindowIconImages(URL svgUrl)
      Creates from the given SVG a list of icon images with different sizes that can be used for windows headers. The SVG should have a size of 16x16, otherwise it is scaled.

      If running on Windows in Java 9 or later and multi-resolution image support is available, then a single multi-resolution image is returned that creates images on demand for requested sizes from SVG. This has the advantage that only images for used sizes are created. Also, if unusual sizes are requested (e.g. 18x18), then they are created from SVG.

      This method is useful if using Java modules and the package containing the SVG is not opened in module-info.java. E.g. createWindowIconImages( getClass().getResource( "/com/myapp/myicon.svg" ) ).

      Parameters:
      svgUrl - the URL of the SVG resource
      Returns:
      list of icon images with different sizes (16x16, 20x20, 24x24, 28x28, 32x32, 48x48 and 64x64)
      Throws:
      RuntimeException - if failed to load or render SVG file
      Since:
      2
      See Also:
    • svg2image

      public static BufferedImage svg2image(String svgName, int width, int height)
      Creates a buffered image and renders the given SVG into it.

      If using Java modules, the package containing the SVG must be opened in module-info.java. Otherwise, use svg2image(URL, int, int).

      Parameters:
      svgName - the name of the SVG resource (a '/'-separated path)
      width - the width of the image
      height - the height of the image
      Returns:
      the image
      Throws:
      RuntimeException - if failed to load or render SVG file
    • svg2image

      public static BufferedImage svg2image(URL svgUrl, int width, int height)
      Creates a buffered image and renders the given SVG into it.

      This method is useful if using Java modules and the package containing the SVG is not opened in module-info.java. E.g. svg2image( getClass().getResource( "/com/myapp/myicon.svg" ), 24, 24 ).

      Parameters:
      svgUrl - the URL of the SVG resource
      width - the width of the image
      height - the height of the image
      Returns:
      the image
      Throws:
      RuntimeException - if failed to load or render SVG file
      Since:
      2
    • svg2image

      public static BufferedImage svg2image(String svgName, float scaleFactor)
      Creates a buffered image and renders the given SVG into it.

      If using Java modules, the package containing the SVG must be opened in module-info.java. Otherwise, use svg2image(URL, float).

      Parameters:
      svgName - the name of the SVG resource (a '/'-separated path)
      scaleFactor - the amount by which the SVG size is scaled
      Returns:
      the image
      Throws:
      RuntimeException - if failed to load or render SVG file
    • svg2image

      public static BufferedImage svg2image(URL svgUrl, float scaleFactor)
      Creates a buffered image and renders the given SVG into it.

      This method is useful if using Java modules and the package containing the SVG is not opened in module-info.java. E.g. svg2image( getClass().getResource( "/com/myapp/myicon.svg" ), 1.5f ).

      Parameters:
      svgUrl - the URL of the SVG resource
      scaleFactor - the amount by which the SVG size is scaled
      Returns:
      the image
      Throws:
      RuntimeException - if failed to load or render SVG file
      Since:
      2
    • svg2image

      private static BufferedImage svg2image(com.github.weisj.jsvg.SVGDocument document, int width, int height)
      Creates a buffered image and renders the given SVGDocument into it.
      Parameters:
      document - the SVG document
      width - the width of the image
      height - the height of the image
      Returns:
      the image
      Throws:
      RuntimeException - if failed to render SVG file
    • getResource

      private static URL getResource(String svgName)