Class SvgIcon

All Implemented Interfaces:
AttachNotifier, ClickNotifier<SvgIcon>, DetachNotifier, HasElement, HasStyle, HasTooltip, Serializable

public class SvgIcon extends AbstractIcon<SvgIcon>
Component for displaying an icon from a SVG file.
Author:
Vaadin Ltd
See Also:
  • Constructor Details

  • Method Details

    • setSrc

      public void setSrc(String src)
      Sets the URL of the SVG file to be used as the icon. The value can be:
      • A path to a standalone SVG file
      • A path in the format `"path/to/file.svg#symbol-id"` to an SVG file, where "symbol-id" refers to an id of an element (generally a `` element) to be rendered in the icon component.

        Note that the sprite file needs to follow the same-origin policy

      • Alternatively, the source can be defined as a string in the format `"data:image/svg+xml,...`
      Parameters:
      src - the source file of the icon
    • setSrc

      public void setSrc(String src, String symbol)
      Defines the src and the symbol to be used in the icon.
      Parameters:
      src - the path of the icon sprite file
      symbol - the symbol reference of the icon
      See Also:
    • setSrc

      public void setSrc(AbstractStreamResource src)
      Defines the source of the icon from the given StreamResource The resource must contain a valid SVG element.
      Parameters:
      src - the source value, not null
    • setSrc

      public void setSrc(AbstractStreamResource src, String symbol)
      Defines the src and the symbol to be used in the icon.
      Parameters:
      src - the source of the icon sprite file, not null
      symbol - the symbol reference of the icon
      See Also:
    • getSrc

      public String getSrc()
      Gets the source defined in the icon.
      Returns:
      the source defined or null
    • setSymbol

      public void setSymbol(String symbol)

      Defines the symbol identifier that references an ID of an element contained in the SVG element assigned to the setSrc(String) property.

      If there's an identifier in the path defined in setSrc(String) in the moment this method is called, the value passed to setSymbol(String) will be used.

      Parameters:
      symbol - the symbol identifier of the icon to be shown
    • getSymbol

      public String getSymbol()
      Gets the symbol defined in the icon.
      Returns:
      the symbol defined or null
    • setColor

      public void setColor(String color)
      Description copied from class: AbstractIcon
      Sets the color of the icon.

      The color should be in a format understood by the browser, e.g. "orange", "#FF9E2C" or "rgb(255, 158, 44)".

      Specified by:
      setColor in class AbstractIcon<SvgIcon>
      Parameters:
      color - the color to set, may be null to clear the value
    • getColor

      public String getColor()
      Description copied from class: AbstractIcon
      Gets the color of this icon as a String.
      Specified by:
      getColor in class AbstractIcon<SvgIcon>
      Returns:
      the color of the icon, or null if the color has not been set