Class Image

All Implemented Interfaces:
AttachNotifier, ClickNotifier<Image>, DetachNotifier, HasAriaLabel, HasComponents, HasElement, HasEnabled, HasSize, HasStyle, HasText, Serializable

@Tag("img") public class Image extends HtmlContainer implements ClickNotifier<Image>, HasAriaLabel
Component representing a <img> element.
Since:
1.0
Author:
Vaadin Ltd
See Also:
  • Constructor Details

    • Image

      public Image()
      Creates a new empty image.
    • Image

      public Image(String src, String alt)
      Creates an image with the given URL and an alternative text.

      The alternative text given to constructor is always set even if it is the default empty string which is not retained with setAlt(String).

      Parameters:
      src - the image URL
      alt - the alternate text
      See Also:
    • Image

      public Image(AbstractStreamResource src, String alt)
      Creates an image with the given stream resource and an alternative text.

      The alternative text given to constructor is always set even if it is the default empty string which is not retained with setAlt(String).

      Parameters:
      src - the resource value, not null
      alt - the alternate text
      See Also:
  • Method Details

    • getSrc

      public String getSrc()
      Gets the image URL.
      Returns:
      the image URL
    • setSrc

      public void setSrc(String src)
      Sets the image URL.
      Parameters:
      src - the image URL
    • setSrc

      public void setSrc(AbstractStreamResource src)
      Sets the image URL with the URL of the given StreamResource.
      Parameters:
      src - the resource value, not null
    • setAlt

      public void setAlt(String alt)
      Sets the alternate text for the image.
      Parameters:
      alt - the alternate text
    • getAlt

      public Optional<String> getAlt()
      Gets the alternate text for the image.
      Returns:
      an optional alternate text, or an empty optional if no alternate text has been set