Class Canvas

java.lang.Object
javafx.scene.Node
javafx.scene.canvas.Canvas
All Implemented Interfaces:
Styleable, EventTarget

public class Canvas extends Node
Canvas is an image that can be drawn on using a set of graphics commands provided by a GraphicsContext.

A Canvas node is constructed with a width and height that specifies the size of the image into which the canvas drawing commands are rendered. All drawing operations are clipped to the bounds of that image.

Example:

import javafx.scene.*;
import javafx.scene.paint.*;
import javafx.scene.canvas.*;

Group root = new Group();
Scene s = new Scene(root, 300, 300, Color.BLACK);

final Canvas canvas = new Canvas(250,250);
GraphicsContext gc = canvas.getGraphicsContext2D();

gc.setFill(Color.BLUE);
gc.fillRect(75,75,100,100);

root.getChildren().add(canvas);
 
Since:
JavaFX 2.2
See Also:
  • Property Details

  • Constructor Details

    • Canvas

      public Canvas()
      Creates an empty instance of Canvas.
    • Canvas

      public Canvas(double width, double height)
      Creates a new instance of Canvas with the given size.
      Parameters:
      width - width of the canvas
      height - height of the canvas
  • Method Details

    • getGraphicsContext2D

      public GraphicsContext getGraphicsContext2D()
      returns the GraphicsContext associated with this Canvas.
      Returns:
      the GraphicsContext associated with this Canvas
    • setWidth

      public final void setWidth(double value)
      Sets the value of the property width.
      Property description:
      Defines the width of the canvas.
      Default value:
      0.0
    • getWidth

      public final double getWidth()
      Gets the value of the property width.
      Property description:
      Defines the width of the canvas.
      Default value:
      0.0
    • widthProperty

      public final DoubleProperty widthProperty()
      Defines the width of the canvas.
      Default value:
      0.0
      See Also:
    • setHeight

      public final void setHeight(double value)
      Sets the value of the property height.
      Property description:
      Defines the height of the canvas.
      Default value:
      0.0
    • getHeight

      public final double getHeight()
      Gets the value of the property height.
      Property description:
      Defines the height of the canvas.
      Default value:
      0.0
    • heightProperty

      public final DoubleProperty heightProperty()
      Defines the height of the canvas.
      Default value:
      0.0
      See Also: