Class Icon

java.lang.Object
com.vaadin.flow.component.Component
com.vaadin.flow.component.icon.AbstractIcon<Icon>
com.vaadin.flow.component.icon.Icon
All Implemented Interfaces:
com.vaadin.flow.component.AttachNotifier, com.vaadin.flow.component.ClickNotifier<Icon>, com.vaadin.flow.component.DetachNotifier, com.vaadin.flow.component.HasElement, com.vaadin.flow.component.HasStyle, com.vaadin.flow.component.shared.HasTooltip, Serializable

@NpmPackage(value="@vaadin/icons", version="25.1.0-alpha7") @JsModule("@vaadin/icons/vaadin-iconset.js") public class Icon extends AbstractIcon<Icon>
Component for displaying an icon from the Vaadin Icons collection.
Author:
Vaadin Ltd
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates an empty Icon.
    Creates an Icon component that displays the given icon from VaadinIcon.
    Icon(com.vaadin.flow.signals.Signal<VaadinIcon> iconSignal)
    Creates an Icon component that displays the icon from the given signal.
    Icon(String icon)
    Creates an Icon component that displays the given icon from vaadin-icons collection.
    Icon(String collection, String icon)
    Creates an Icon component that displays the given icon from the given collection.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    bindIcon(com.vaadin.flow.signals.Signal<VaadinIcon> signal)
    Binds the given signal to the icon of the component.
    Gets the collection of the icon (the part before :).
    Gets the color of this icon as a String.
    Gets the full icon name, including the collection.
    void
    Sets the color of the icon.
    void
    Sets the icon to the given Vaadin icon.
    void
    Sets the icon to the given icon.
    void
    setIcon(String collection, String icon)
    Sets the icon to the given icon from the given collection.

    Methods inherited from class com.vaadin.flow.component.icon.AbstractIcon

    setSize

    Methods inherited from class com.vaadin.flow.component.Component

    addListener, bindVisible, findAncestor, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getListeners, getLocale, getParent, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onAttach, onDetach, onEnabledStateChanged, removeFromParent, scrollIntoView, scrollIntoView, set, setElement, setId, setVisible

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface com.vaadin.flow.component.AttachNotifier

    addAttachListener

    Methods inherited from interface com.vaadin.flow.component.ClickNotifier

    addClickListener, addClickShortcut, addDoubleClickListener, addSingleClickListener

    Methods inherited from interface com.vaadin.flow.component.DetachNotifier

    addDetachListener

    Methods inherited from interface com.vaadin.flow.component.HasElement

    getElement

    Methods inherited from interface com.vaadin.flow.component.HasStyle

    addClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassName

    Methods inherited from interface com.vaadin.flow.component.shared.HasTooltip

    getTooltip, setTooltipMarkdown, setTooltipText
  • Constructor Details

    • Icon

      public Icon()
      Creates an empty Icon.
    • Icon

      public Icon(VaadinIcon icon)
      Creates an Icon component that displays the given icon from VaadinIcon.
      Parameters:
      icon - the icon to display
    • Icon

      public Icon(com.vaadin.flow.signals.Signal<VaadinIcon> iconSignal)
      Creates an Icon component that displays the icon from the given signal.

      The icon is kept synchronized with the signal value while the component is attached. When the component is detached, signal value changes have no effect.

      Parameters:
      iconSignal - the signal providing the icon to display
      Since:
      25.1
      See Also:
    • Icon

      public Icon(String icon)
      Creates an Icon component that displays the given icon from vaadin-icons collection.
      Parameters:
      icon - the icon name
    • Icon

      public Icon(String collection, String icon)
      Creates an Icon component that displays the given icon from the given collection. If you want to use a custom <vaadin-iconset> -based icon set, you also need to add a dependency and an import for it, example:
       
       @NpmPackage(value = "custom-icons", version = "1.0.0")
       @JsModule("custom-icons/iconset.js")
       public class MyView extends Div {
       
       
      Parameters:
      collection - the icon collection
      icon - the icon name
  • Method Details

    • setIcon

      public void setIcon(String icon)
      Sets the icon to the given icon.

      If the icon name contains a ":", the first part is used as the collection and the second part as the icon name. If the icon name does not contain a ":", the current collection is used (vaadin by default).

      Parameters:
      icon - the icon name
    • setIcon

      public void setIcon(VaadinIcon icon)
      Sets the icon to the given Vaadin icon.
      Parameters:
      icon - the icon name
    • bindIcon

      public void bindIcon(com.vaadin.flow.signals.Signal<VaadinIcon> signal)
      Binds the given signal to the icon of the component.

      When a signal is bound, the icon is kept synchronized with the signal value while the component is attached. When the component is detached, signal value changes have no effect.

      While a signal is bound, any attempt to set the icon manually through setIcon(VaadinIcon) throws a BindingActiveException.

      Parameters:
      signal - the signal to bind the icon to, not null
      Since:
      25.1
      See Also:
    • getIcon

      public String getIcon()
      Gets the full icon name, including the collection.
      Returns:
      the icon name or null if no icon is set
    • setIcon

      public void setIcon(String collection, String icon)
      Sets the icon to the given icon from the given collection. If you want to use a custom <vaadin-iconset> -based icon set, you also need to add a dependency and an import for it, example:
       
       @NpmPackage(value = "custom-icons", version = "1.0.0")
       @JsModule("custom-icons/iconset.js")
       public class MyView extends Div {
       
       
      Parameters:
      collection - the icon collection
      icon - the icon name
    • getCollection

      public String getCollection()
      Gets the collection of the icon (the part before :).
      Returns:
      the collection of the icon or null if no collection is set
    • 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<Icon>
      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<Icon>
      Returns:
      the color of the icon, or null if the color has not been set