Class Canvas<T extends Canvas<T>>


public class Canvas<T extends Canvas<T>> extends StyledElement<T>
Represents the HTML <canvas> element for drawing graphics via scripting.

The Canvas class provides a Java representation of the HTML canvas element, which is used to draw graphics, animations, and other visual content dynamically using JavaScript. The canvas provides a bitmap drawing surface that can be manipulated through the Canvas API.

Features:

  • Configurable width and height in pixels
  • Bitmap drawing surface for JavaScript graphics
  • Support for 2D and WebGL rendering contexts
  • Dynamic content generation capability
  • Animation and game graphics support
  • Image manipulation and processing
  • Data visualization capabilities

Usage Example:


 // Create a canvas for drawing
 Canvas drawingCanvas = new Canvas();
 drawingCanvas.setIntrinsicWidth(800);
 drawingCanvas.setIntrinsicHeight(600);
 drawingCanvas.setId("myCanvas");

 // Create a canvas for a chart
 Canvas chartCanvas = new Canvas();
 chartCanvas.setIntrinsicWidth(400);
 chartCanvas.setIntrinsicHeight(300);
 chartCanvas.setClass("chart-canvas");

 // Create a canvas for game graphics
 Canvas gameCanvas = new Canvas();
 gameCanvas.setIntrinsicWidth(1024);
 gameCanvas.setIntrinsicHeight(768);
 gameCanvas.setId("gameCanvas");

 // Note: Actual drawing is performed via JavaScript
 // using the Canvas 2D or WebGL rendering context
 
Since:
2007
Version:
1.0
Author:
Marvin P. Warble Jr.
See Also:
  • EmbeddedElement
  • Constructor Details

    • Canvas

      public Canvas()
      Constructs a new canvas element.
  • Method Details

    • setIntrinsicWidth

      public T setIntrinsicWidth(int pixels)
      Sets the HTML width attribute to specify intrinsic width in pixels.

      This sets the HTML attribute (e.g., <img width="300">), not the CSS width property. To set CSS width, use the inherited StyledElement.setWidth(int) method.

      Parameters:
      pixels - The width in pixels.
      Returns:
      This element for method chaining.
    • setIntrinsicWidth

      public T setIntrinsicWidth(String width)
      Sets the HTML width attribute to specify intrinsic width.

      This sets the HTML attribute, not the CSS width property. To set CSS width, use the inherited StyledElement.setWidth(String) method.

      Parameters:
      width - The width value.
      Returns:
      This element for method chaining.
    • setIntrinsicHeight

      public T setIntrinsicHeight(int pixels)
      Sets the HTML height attribute to specify intrinsic height in pixels.

      This sets the HTML attribute (e.g., <img height="200">), not the CSS height property. To set CSS height, use the inherited StyledElement.setHeight(int) method.

      Parameters:
      pixels - The height in pixels.
      Returns:
      This element for method chaining.
    • setIntrinsicHeight

      public T setIntrinsicHeight(String height)
      Sets the HTML height attribute to specify intrinsic height.

      This sets the HTML attribute, not the CSS height property. To set CSS height, use the inherited StyledElement.setHeight(String) method.

      Parameters:
      height - The height value.
      Returns:
      This element for method chaining.
    • getIntrinsicWidth

      public String getIntrinsicWidth()
      Returns the HTML width attribute value.

      Returns the intrinsic width set via the HTML attribute, not the CSS width.

      Returns:
      The width value, or null if not set.
    • getIntrinsicHeight

      public String getIntrinsicHeight()
      Returns the HTML height attribute value.

      Returns the intrinsic height set via the HTML attribute, not the CSS height.

      Returns:
      The height value, or null if not set.