Class ImageElement

java.lang.Object
com.vaadin.flow.dom.Node<com.vaadin.flow.dom.Element>
com.vaadin.flow.dom.Element
All Implemented Interfaces:
Serializable

public class ImageElement extends SvgGraphicsElement
A typed Java API for the SVG <image> element.

The <image> element includes images inside SVG documents. It can display raster image files (PNG, JPEG) or other SVG files.

Write-Only vs Read-Write Methods

This class provides two variants for each attribute setter:

  • Default methods (e.g., x(), y()) - Use an optimized write-only approach. Attribute values are NOT stored on the server and cannot be retrieved via getAttribute().
  • RW methods (e.g., xRW(), yRW()) - Use traditional setAttribute() which stores values on the server for later retrieval.
See Also:
  • Constructor Details

    • ImageElement

      public ImageElement()
    • ImageElement

      public ImageElement(String href)
      Creates an image element with the given href.
      Parameters:
      href - the URL of the image
    • ImageElement

      public ImageElement(String href, double x, double y, double width, double height)
      Creates an image element with position and size.
      Parameters:
      href - the URL of the image
      x - the x coordinate
      y - the y coordinate
      width - the width
      height - the height
  • Method Details

    • href

      public ImageElement href(String href)
      Sets the URL of the image.

      Uses write-only optimization. Use hrefRW(String) if you need to read the value back.

      Parameters:
      href - the image URL
      Returns:
      this element for method chaining
    • hrefRW

      public ImageElement hrefRW(String href)
      Sets the URL of the image (read-write).
      Parameters:
      href - the image URL
      Returns:
      this element for method chaining
    • x

      public ImageElement x(double x)
      Sets the x coordinate of the image.

      Uses write-only optimization. Use xRW(double) if you need to read the value back.

      Parameters:
      x - the x coordinate
      Returns:
      this element for method chaining
    • x

      public ImageElement x(String x)
      Sets the x coordinate with a unit.

      Uses write-only optimization. Use xRW(String) if you need to read the value back.

      Parameters:
      x - the x coordinate (e.g., "10%")
      Returns:
      this element for method chaining
    • xRW

      public ImageElement xRW(double x)
      Sets the x coordinate of the image (read-write).
      Parameters:
      x - the x coordinate
      Returns:
      this element for method chaining
    • xRW

      public ImageElement xRW(String x)
      Sets the x coordinate with a unit (read-write).
      Parameters:
      x - the x coordinate (e.g., "10%")
      Returns:
      this element for method chaining
    • y

      public ImageElement y(double y)
      Sets the y coordinate of the image.

      Uses write-only optimization. Use yRW(double) if you need to read the value back.

      Parameters:
      y - the y coordinate
      Returns:
      this element for method chaining
    • y

      public ImageElement y(String y)
      Sets the y coordinate with a unit.

      Uses write-only optimization. Use yRW(String) if you need to read the value back.

      Parameters:
      y - the y coordinate (e.g., "10%")
      Returns:
      this element for method chaining
    • yRW

      public ImageElement yRW(double y)
      Sets the y coordinate of the image (read-write).
      Parameters:
      y - the y coordinate
      Returns:
      this element for method chaining
    • yRW

      public ImageElement yRW(String y)
      Sets the y coordinate with a unit (read-write).
      Parameters:
      y - the y coordinate (e.g., "10%")
      Returns:
      this element for method chaining
    • width

      public ImageElement width(double width)
      Sets the width of the image.

      Uses write-only optimization. Use widthRW(double) if you need to read the value back.

      Overrides:
      width in class SvgElement
      Parameters:
      width - the width
      Returns:
      this element for method chaining
    • width

      public ImageElement width(String width)
      Sets the width with a unit.

      Uses write-only optimization. Use widthRW(String) if you need to read the value back.

      Overrides:
      width in class SvgElement
      Parameters:
      width - the width (e.g., "100%", "200px")
      Returns:
      this element for method chaining
    • widthRW

      public ImageElement widthRW(double width)
      Sets the width of the image (read-write).
      Parameters:
      width - the width
      Returns:
      this element for method chaining
    • widthRW

      public ImageElement widthRW(String width)
      Sets the width with a unit (read-write).
      Parameters:
      width - the width (e.g., "100%", "200px")
      Returns:
      this element for method chaining
    • height

      public ImageElement height(double height)
      Sets the height of the image.

      Uses write-only optimization. Use heightRW(double) if you need to read the value back.

      Overrides:
      height in class SvgElement
      Parameters:
      height - the height
      Returns:
      this element for method chaining
    • height

      public ImageElement height(String height)
      Sets the height with a unit.

      Uses write-only optimization. Use heightRW(String) if you need to read the value back.

      Overrides:
      height in class SvgElement
      Parameters:
      height - the height (e.g., "100%", "200px")
      Returns:
      this element for method chaining
    • heightRW

      public ImageElement heightRW(double height)
      Sets the height of the image (read-write).
      Parameters:
      height - the height
      Returns:
      this element for method chaining
    • heightRW

      public ImageElement heightRW(String height)
      Sets the height with a unit (read-write).
      Parameters:
      height - the height (e.g., "100%", "200px")
      Returns:
      this element for method chaining
    • position

      public ImageElement position(double x, double y)
      Sets the position of the image.

      Uses write-only optimization. Use positionRW(double, double) if you need to read the values back.

      Parameters:
      x - the x coordinate
      y - the y coordinate
      Returns:
      this element for method chaining
    • positionRW

      public ImageElement positionRW(double x, double y)
      Sets the position of the image (read-write).
      Parameters:
      x - the x coordinate
      y - the y coordinate
      Returns:
      this element for method chaining
    • size

      public ImageElement size(double width, double height)
      Sets the size of the image.

      Uses write-only optimization. Use sizeRW(double, double) if you need to read the values back.

      Overrides:
      size in class SvgElement
      Parameters:
      width - the width
      height - the height
      Returns:
      this element for method chaining
    • sizeRW

      public ImageElement sizeRW(double width, double height)
      Sets the size of the image (read-write).
      Parameters:
      width - the width
      height - the height
      Returns:
      this element for method chaining
    • bounds

      public ImageElement bounds(double x, double y, double width, double height)
      Sets the bounds of the image (position and size).

      Uses write-only optimization. Use boundsRW(double, double, double, double) if you need to read the values back.

      Parameters:
      x - the x coordinate
      y - the y coordinate
      width - the width
      height - the height
      Returns:
      this element for method chaining
    • boundsRW

      public ImageElement boundsRW(double x, double y, double width, double height)
      Sets the bounds of the image (position and size) (read-write).
      Parameters:
      x - the x coordinate
      y - the y coordinate
      width - the width
      height - the height
      Returns:
      this element for method chaining
    • preserveAspectRatio

      public ImageElement preserveAspectRatio(String preserveAspectRatio)
      Sets how the image should be scaled to fit.

      Uses write-only optimization. Use preserveAspectRatioRW(String) if you need to read the value back.

      Overrides:
      preserveAspectRatio in class SvgElement
      Parameters:
      preserveAspectRatio - the preserveAspectRatio value (e.g., "xMidYMid meet")
      Returns:
      this element for method chaining
    • preserveAspectRatioRW

      public ImageElement preserveAspectRatioRW(String preserveAspectRatio)
      Sets how the image should be scaled to fit (read-write).
      Parameters:
      preserveAspectRatio - the preserveAspectRatio value (e.g., "xMidYMid meet")
      Returns:
      this element for method chaining
    • preserveAspectRatio

      public ImageElement preserveAspectRatio(SvgElement.PreserveAspectRatio ratio)
      Sets how the image should be scaled to fit.

      Uses write-only optimization. Use preserveAspectRatioRW(PreserveAspectRatio) if you need to read the value back.

      Overrides:
      preserveAspectRatio in class SvgElement
      Parameters:
      ratio - the preserveAspectRatio setting
      Returns:
      this element for method chaining
    • preserveAspectRatioRW

      public ImageElement preserveAspectRatioRW(SvgElement.PreserveAspectRatio ratio)
      Sets how the image should be scaled to fit (read-write).
      Parameters:
      ratio - the preserveAspectRatio setting
      Returns:
      this element for method chaining
    • crossorigin

      public ImageElement crossorigin(String crossorigin)
      Sets the crossorigin attribute for CORS requests.

      Uses write-only optimization. Use crossoriginRW(String) if you need to read the value back.

      Parameters:
      crossorigin - the crossorigin value ("anonymous" or "use-credentials")
      Returns:
      this element for method chaining
    • crossoriginRW

      public ImageElement crossoriginRW(String crossorigin)
      Sets the crossorigin attribute for CORS requests (read-write).
      Parameters:
      crossorigin - the crossorigin value ("anonymous" or "use-credentials")
      Returns:
      this element for method chaining