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);
GraphicsContext
Type | Property and Description |
---|---|
DoubleProperty |
height
Defines the height of the canvas.
|
DoubleProperty |
width
Defines the width of the canvas.
|
Modifier and Type | Field and Description |
---|---|
private GrowableDataBuffer |
current |
(package private) static int |
DEFAULT_OBJ_BUF_SIZE |
(package private) static int |
DEFAULT_VAL_BUF_SIZE |
private DoubleProperty |
height
Defines the height of the canvas.
|
private int |
lastsizeindex |
private int[] |
recentobjsizes |
private int[] |
recentvalsizes |
private boolean |
rendererBehind |
private static int |
SIZE_HISTORY |
private GraphicsContext |
theContext |
private DoubleProperty |
width
Defines the width of the canvas.
|
Constructor and Description |
---|
Canvas()
Creates an empty instance of Canvas.
|
Canvas(double width,
double height)
Creates a new instance of Canvas with the given size.
|
Modifier and Type | Method and Description |
---|---|
private boolean |
doComputeContains(double localX,
double localY) |
private BaseBounds |
doComputeGeomBounds(BaseBounds bounds,
BaseTransform tx) |
private NGNode |
doCreatePeer() |
private void |
doUpdatePeer() |
(package private) GrowableDataBuffer |
getBuffer() |
GraphicsContext |
getGraphicsContext2D()
returns the
GraphicsContext associated with this Canvas . |
double |
getHeight()
Gets the value of the property height.
|
double |
getWidth()
Gets the value of the property width.
|
DoubleProperty |
heightProperty()
Defines the height of the canvas.
|
(package private) boolean |
isRendererFallingBehind() |
private static int |
max(int[] sizes,
int defsize) |
void |
setHeight(double value)
Sets the value of the property height.
|
void |
setWidth(double value)
Sets the value of the property width.
|
DoubleProperty |
widthProperty()
Defines the width of the canvas.
|
public final DoubleProperty widthProperty
getWidth()
,
setWidth(double)
public final DoubleProperty heightProperty
getHeight()
,
setHeight(double)
static final int DEFAULT_VAL_BUF_SIZE
static final int DEFAULT_OBJ_BUF_SIZE
private static final int SIZE_HISTORY
private GrowableDataBuffer current
private boolean rendererBehind
private int[] recentvalsizes
private int[] recentobjsizes
private int lastsizeindex
private GraphicsContext theContext
private DoubleProperty width
private DoubleProperty height
public Canvas()
public Canvas(double width, double height)
width
- width of the canvasheight
- height of the canvasprivate static int max(int[] sizes, int defsize)
GrowableDataBuffer getBuffer()
boolean isRendererFallingBehind()
public GraphicsContext getGraphicsContext2D()
GraphicsContext
associated with this Canvas
.GraphicsContext
associated with this Canvas
public final void setWidth(double value)
public final double getWidth()
public final DoubleProperty widthProperty()
getWidth()
,
setWidth(double)
public final void setHeight(double value)
public final double getHeight()
public final DoubleProperty heightProperty()
getHeight()
,
setHeight(double)
private NGNode doCreatePeer()
private void doUpdatePeer()
private boolean doComputeContains(double localX, double localY)
private BaseBounds doComputeGeomBounds(BaseBounds bounds, BaseTransform tx)