APIdia Launch Partner
Top Description Fields Constructors Methods
javafx.scene.canvas

public non-sealed Class Canvas

extends Node
Class Inheritance
Imports
javafx.beans.property.DoubleProperty, .DoublePropertyBase, javafx.geometry.NodeOrientation, javafx.scene.Node, com.sun.javafx.geom.BaseBounds, .RectBounds, com.sun.javafx.geom.transform.BaseTransform, com.sun.javafx.scene.DirtyBits, .NodeHelper, com.sun.javafx.scene.canvas.CanvasHelper, com.sun.javafx.sg.prism.GrowableDataBuffer, .NGCanvas, .NGNode

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
GraphicsContext

Field Summary

Modifier and TypeField and Description
private GrowableDataBuffer
pack-priv static final int
pack-priv static final int
private DoubleProperty
height

Defines the height of the canvas.

private int
private int[]
private int[]
private boolean
private static final int
private GraphicsContext
private DoubleProperty
width

Defines the width of the canvas.

Inherited from javafx.scene.Node:
BASELINE_OFFSET_SAME_AS_HEIGHT

Constructor Summary

AccessConstructor and Description
public
Canvas()

Creates an empty instance of Canvas.

public
Canvas(double
width of the canvas
width
,
double
height of the canvas
height
)

Creates a new instance of Canvas with the given size.

Method Summary

Modifier and TypeMethod and Description
private boolean
doComputeContains(double localX, double localY)

private BaseBounds
private NGNode
private void
pack-priv GrowableDataBuffer
public GraphicsContext

Returns:

the GraphicsContext associated with this Canvas
getGraphicsContext2D
()

returns the GraphicsContext associated with this Canvas.

public final double
public final double
public final DoubleProperty
pack-priv boolean
private static int
max(int[] sizes, int defsize)

public final void
setHeight(double value)

public final void
setWidth(double value)

public final DoubleProperty
Inherited from javafx.scene.Node:
accessibleHelpPropertyaccessibleRoleDescriptionPropertyaccessibleRolePropertyaccessibleTextPropertyaddEventFilteraddEventHandlerapplyCssautosizeblendModePropertyboundsInLocalPropertyboundsInParentPropertybuildEventDispatchChaincacheHintPropertycachePropertyclipPropertycomputeAreaInScreencontainscontainscursorPropertydepthTestPropertydisabledPropertydisablePropertyeffectiveNodeOrientationPropertyeffectPropertyeventDispatcherPropertyexecuteAccessibleActionfireEventfocusedPropertyfocusTraversablePropertyfocusVisiblePropertyfocusWithinPropertygetAccessibleHelpgetAccessibleRolegetAccessibleRoleDescriptiongetAccessibleTextgetBaselineOffsetgetBlendModegetBoundsInLocalgetBoundsInParentgetCacheHintgetClassCssMetaDatagetClipgetContentBiasgetCssMetaDatagetCursorgetDepthTestgetEffectgetEffectiveNodeOrientationgetEventDispatchergetIdgetInitialCursorgetInitialFocusTraversablegetInputMethodRequestsgetLayoutBoundsgetLayoutXgetLayoutYgetLocalToParentTransformgetLocalToSceneTransformgetNodeOrientationgetOnContextMenuRequestedgetOnDragDetectedgetOnDragDonegetOnDragDroppedgetOnDragEnteredgetOnDragExitedgetOnDragOvergetOnInputMethodTextChangedgetOnKeyPressedgetOnKeyReleasedgetOnKeyTypedgetOnMouseClickedgetOnMouseDragDonegetOnMouseDragEnteredgetOnMouseDragExitedgetOnMouseDraggedgetOnMouseDragOvergetOnMouseDragReleasedgetOnMouseEnteredgetOnMouseExitedgetOnMouseMovedgetOnMousePressedgetOnMouseReleasedgetOnRotategetOnRotationFinishedgetOnRotationStartedgetOnScrollgetOnScrollFinishedgetOnScrollStartedgetOnSwipeDowngetOnSwipeLeftgetOnSwipeRightgetOnSwipeUpgetOnTouchMovedgetOnTouchPressedgetOnTouchReleasedgetOnTouchStationarygetOnZoomgetOnZoomFinishedgetOnZoomStartedgetOpacitygetParentgetPropertiesgetPseudoClassStatesgetRotategetRotationAxisgetScaleXgetScaleYgetScaleZgetScenegetStylegetStyleableParentgetStyleClassgetTransformsgetTranslateXgetTranslateYgetTranslateZgetTypeSelectorgetUserDatagetViewOrderhasPropertieshoverPropertyidPropertyinputMethodRequestsPropertyintersectsintersectsisCacheisDisableisDisabledisFocusedisFocusTraversableisFocusVisibleisFocusWithinisHoverisManagedisMouseTransparentisPickOnBoundsisPressedisResizableisVisiblelayoutBoundsPropertylayoutXPropertylayoutYPropertylocalToParentlocalToParentlocalToParentlocalToParentlocalToParentlocalToParentTransformPropertylocalToScenelocalToScenelocalToScenelocalToScenelocalToScenelocalToScenelocalToScenelocalToScenelocalToScenelocalToScenelocalToSceneTransformPropertylocalToScreenlocalToScreenlocalToScreenlocalToScreenlocalToScreenlookuplookupAllmanagedPropertymaxHeightmaxWidthminHeightminWidthmouseTransparentPropertynodeOrientationPropertynotifyAccessibleAttributeChangedonContextMenuRequestedPropertyonDragDetectedPropertyonDragDonePropertyonDragDroppedPropertyonDragEnteredPropertyonDragExitedPropertyonDragOverPropertyonInputMethodTextChangedPropertyonKeyPressedPropertyonKeyReleasedPropertyonKeyTypedPropertyonMouseClickedPropertyonMouseDragDonePropertyonMouseDragEnteredPropertyonMouseDragExitedPropertyonMouseDraggedPropertyonMouseDragOverPropertyonMouseDragReleasedPropertyonMouseEnteredPropertyonMouseExitedPropertyonMouseMovedPropertyonMousePressedPropertyonMouseReleasedPropertyonRotatePropertyonRotationFinishedPropertyonRotationStartedPropertyonScrollFinishedPropertyonScrollPropertyonScrollStartedPropertyonSwipeDownPropertyonSwipeLeftPropertyonSwipeRightPropertyonSwipeUpPropertyonTouchMovedPropertyonTouchPressedPropertyonTouchReleasedPropertyonTouchStationaryPropertyonZoomFinishedPropertyonZoomPropertyonZoomStartedPropertyopacityPropertyparentPropertyparentToLocalparentToLocalparentToLocalparentToLocalparentToLocalpickOnBoundsPropertyprefHeightprefWidthpressedPropertypseudoClassStateChangedqueryAccessibleAttributerelocateremoveEventFilterremoveEventHandlerrequestFocusrequestFocusTraversalresizeresizeRelocaterotatePropertyrotationAxisPropertyscaleXPropertyscaleYPropertyscaleZPropertyscenePropertysceneToLocalsceneToLocalsceneToLocalsceneToLocalsceneToLocalsceneToLocalsceneToLocalsceneToLocalscreenToLocalscreenToLocalscreenToLocalsetAccessibleHelpsetAccessibleRolesetAccessibleRoleDescriptionsetAccessibleTextsetBlendModesetCachesetCacheHintsetClipsetCursorsetDepthTestsetDisablesetDisabledsetEffectsetEventDispatchersetEventHandlersetFocusedsetFocusTraversablesetHoversetIdsetInputMethodRequestssetLayoutXsetLayoutYsetManagedsetMouseTransparentsetNodeOrientationsetOnContextMenuRequestedsetOnDragDetectedsetOnDragDonesetOnDragDroppedsetOnDragEnteredsetOnDragExitedsetOnDragOversetOnInputMethodTextChangedsetOnKeyPressedsetOnKeyReleasedsetOnKeyTypedsetOnMouseClickedsetOnMouseDragDonesetOnMouseDragEnteredsetOnMouseDragExitedsetOnMouseDraggedsetOnMouseDragOversetOnMouseDragReleasedsetOnMouseEnteredsetOnMouseExitedsetOnMouseMovedsetOnMousePressedsetOnMouseReleasedsetOnRotatesetOnRotationFinishedsetOnRotationStartedsetOnScrollsetOnScrollFinishedsetOnScrollStartedsetOnSwipeDownsetOnSwipeLeftsetOnSwipeRightsetOnSwipeUpsetOnTouchMovedsetOnTouchPressedsetOnTouchReleasedsetOnTouchStationarysetOnZoomsetOnZoomFinishedsetOnZoomStartedsetOpacitysetPickOnBoundssetPressedsetRotatesetRotationAxissetScaleXsetScaleYsetScaleZsetStylesetTranslateXsetTranslateYsetTranslateZsetUserDatasetViewOrdersetVisiblesnapshotsnapshotstartDragAndDropstartFullDragstylePropertytoBacktoFronttoStringtranslateXPropertytranslateYPropertytranslateZPropertyusesMirroringviewOrderPropertyvisibleProperty

Field Detail

currentback to summary
private GrowableDataBuffer current
DEFAULT_OBJ_BUF_SIZEback to summary
pack-priv static final int DEFAULT_OBJ_BUF_SIZE
DEFAULT_VAL_BUF_SIZEback to summary
pack-priv static final int DEFAULT_VAL_BUF_SIZE
heightback to summary
private DoubleProperty height

Defines the height of the canvas.

Default Value
0.0
lastsizeindexback to summary
private int lastsizeindex
recentobjsizesback to summary
private int[] recentobjsizes
recentvalsizesback to summary
private int[] recentvalsizes
rendererBehindback to summary
private boolean rendererBehind
SIZE_HISTORYback to summary
private static final int SIZE_HISTORY
theContextback to summary
private GraphicsContext theContext
widthback to summary
private DoubleProperty width

Defines the width of the canvas.

Default Value
0.0

Constructor Detail

Canvasback to summary
public Canvas()

Creates an empty instance of Canvas.

Canvasback to summary
public Canvas(double width, double height)

Creates a new instance of Canvas with the given size.

Parameters
width:double

width of the canvas

height:double

height of the canvas

Method Detail

doComputeContainsback to summary
private boolean doComputeContains(double localX, double localY)
doComputeGeomBoundsback to summary
private BaseBounds doComputeGeomBounds(BaseBounds bounds, BaseTransform tx)
doCreatePeerback to summary
private NGNode doCreatePeer()
doUpdatePeerback to summary
private void doUpdatePeer()

Hides javafx.scene.Node.doUpdatePeer.

getBufferback to summary
pack-priv GrowableDataBuffer getBuffer()
getGraphicsContext2Dback to summary
public GraphicsContext getGraphicsContext2D()

returns the GraphicsContext associated with this Canvas.

Returns:GraphicsContext

the GraphicsContext associated with this Canvas

getHeightback to summary
public final double getHeight()
getWidthback to summary
public final double getWidth()
heightPropertyback to summary
public final DoubleProperty heightProperty()
isRendererFallingBehindback to summary
pack-priv boolean isRendererFallingBehind()
maxback to summary
private static int max(int[] sizes, int defsize)
setHeightback to summary
public final void setHeight(double value)
setWidthback to summary
public final void setWidth(double value)
widthPropertyback to summary
public final DoubleProperty widthProperty()