APIdia Launch Partner
Top Description Inners Fields Constructors Methods
javafx.scene.image

public non-sealed Class ImageView

extends Node
Class Inheritance
Annotations
@DefaultProperty:image
Imports
java.util.List, javafx.beans.DefaultProperty, .Observable, javafx.beans.property.BooleanProperty, .DoubleProperty, .DoublePropertyBase, .ObjectProperty, .ObjectPropertyBase, .StringProperty, javafx.css.CssMetaData, .Styleable, .StyleableBooleanProperty, .StyleableDoubleProperty, .StyleableProperty, .StyleableStringProperty, javafx.css.converter.BooleanConverter, .SizeConverter, .URLConverter, javafx.geometry.NodeOrientation, .Rectangle2D, javafx.scene.AccessibleRole, .Node, com.sun.javafx.beans.event.AbstractNotifyListener, com.sun.javafx.css.CssUtil, .StyleManager, com.sun.javafx.geom.BaseBounds, com.sun.javafx.geom.transform.BaseTransform, com.sun.javafx.scene.DirtyBits, .ImageViewHelper, .NodeHelper, com.sun.javafx.sg.prism.NGImageView, .NGNode, com.sun.javafx.tk.Toolkit

The ImageView is a Node used for painting images loaded with Image class.

This class allows resizing the displayed image (with or without preserving the original aspect ratio) and specifying a viewport into the source image for restricting the pixels displayed by this ImageView.

Example code for displaying images


import javafx.application.Application;
import javafx.geometry.Rectangle2D;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.HBox;
import javafx.scene.paint.Color;
import javafx.stage.Stage;

public class HelloImageView extends Application {

    @Override public void start(Stage stage) {
        // load the image
        Image image = new Image("flower.png");

        // simple displays ImageView the image as is
        ImageView iv1 = new ImageView();
        iv1.setImage(image);

        // resizes the image to have width of 100 while preserving the ratio and using
        // higher quality filtering method; this ImageView is also cached to
        // improve performance
        ImageView iv2 = new ImageView();
        iv2.setImage(image);
        iv2.setFitWidth(100);
        iv2.setPreserveRatio(true);
        iv2.setSmooth(true);
        iv2.setCache(true);

        // defines a viewport into the source image (achieving a "zoom" effect) and
        // displays it rotated
        ImageView iv3 = new ImageView();
        iv3.setImage(image);
        Rectangle2D viewportRect = new Rectangle2D(40, 35, 110, 110);
        iv3.setViewport(viewportRect);
        iv3.setRotate(90);

        Group root = new Group();
        Scene scene = new Scene(root);
        scene.setFill(Color.BLACK);
        HBox box = new HBox();
        box.getChildren().add(iv1);
        box.getChildren().add(iv2);
        box.getChildren().add(iv3);
        root.getChildren().add(box);

        stage.setTitle("ImageView");
        stage.setWidth(415);
        stage.setHeight(200);
        stage.setScene(scene);
        stage.sizeToScene();
        stage.show();
    }

    public static void main(String[] args) {
        Application.launch(args);
    }
}

The code above produces the following:

A visual rendering of the ImageView example

Since
JavaFX 2.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private static final String
private double
private double
private StyleableDoubleProperty
fitHeight

The height of the bounding box within which the source image is resized as necessary to fit.

private StyleableDoubleProperty
fitWidth

The width of the bounding box within which the source image is resized as necessary to fit.

private ObjectProperty<Image>
image

The Image to be painted by this ImageView.

private StringProperty
private Image
private final AbstractNotifyListener
private StyleableBooleanProperty
preserveRatio

Indicates whether to preserve the aspect ratio of the source image when scaling to fit the image within the fitting bounding box.

private StyleableBooleanProperty
smooth

Indicates whether to use a better quality filtering algorithm or a faster one when transforming or scaling the source image to fit within the bounding box provided by fitWidth and fitHeight.

public static final boolean
SMOOTH_DEFAULT

Platform-dependent default value of the smooth property.

private boolean
private ObjectProperty<Rectangle2D>
viewport

The rectangular viewport into the image.

private DoubleProperty
x

The current x coordinate of the ImageView origin.

private DoubleProperty
y

The current y coordinate of the ImageView origin.

Inherited from javafx.scene.Node:
BASELINE_OFFSET_SAME_AS_HEIGHT

Constructor Summary

AccessConstructor and Description
public
ImageView()

Allocates a new ImageView object.

public
ImageView(String
the string representing the URL from which to load the image
url
)

Allocates a new ImageView object with image loaded from the specified URL.

public
ImageView(Image
Image that this ImageView uses
image
)

Allocates a new ImageView object using the given image.

Method Summary

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

private BaseBounds
private NGNode
private void
public final DoubleProperty
public final DoubleProperty
public static List<CssMetaData<? extends Styleable, ?>>

Returns:

the CssMetaData
getClassCssMetaData
()

Hides javafx.scene.Node.getClassCssMetaData.

Gets the CssMetaData associated with this class, which may include the CssMetaData of its superclasses.

public List<CssMetaData<? extends Styleable, ?>>

Returns:

the CssMetaData associated with this class, which may include the CssMetaData of its super classes.
getCssMetaData
()

Overrides javafx.scene.Node.getCssMetaData.

Implements javafx.css.Styleable.getCssMetaData.

This method should delegate to Node#getClassCssMetaData() so that a Node's CssMetaData can be accessed without the need for reflection.

public final double
public final double
public final Image
public final Rectangle2D
public final double
getX()

public final double
getY()

public final ObjectProperty<Image>
private StringProperty
imageUrlProperty()

The imageUrl property is set from CSS and then the image property is set from the invalidated method.

private void
public final boolean
public final boolean
public final BooleanProperty
private void
public final void
setFitHeight(double value)

public final void
setFitWidth(double value)

public final void
setImage(Image value)

public final void
setPreserveRatio(boolean value)

public final void
setSmooth(boolean value)

public final void
public final void
setX(double value)

public final void
setY(double value)

public final BooleanProperty
pack-priv void
public final ObjectProperty<Rectangle2D>
public final DoubleProperty
public final DoubleProperty
Inherited from javafx.scene.Node:
accessibleHelpPropertyaccessibleRoleDescriptionPropertyaccessibleRolePropertyaccessibleTextPropertyaddEventFilteraddEventHandlerapplyCssautosizeblendModePropertyboundsInLocalPropertyboundsInParentPropertybuildEventDispatchChaincacheHintPropertycachePropertyclipPropertycomputeAreaInScreencontainscontainscursorPropertydepthTestPropertydisabledPropertydisablePropertyeffectiveNodeOrientationPropertyeffectPropertyeventDispatcherPropertyexecuteAccessibleActionfireEventfocusedPropertyfocusTraversablePropertyfocusVisiblePropertyfocusWithinPropertygetAccessibleHelpgetAccessibleRolegetAccessibleRoleDescriptiongetAccessibleTextgetBaselineOffsetgetBlendModegetBoundsInLocalgetBoundsInParentgetCacheHintgetClipgetContentBiasgetCursorgetDepthTestgetEffectgetEffectiveNodeOrientationgetEventDispatchergetIdgetInitialCursorgetInitialFocusTraversablegetInputMethodRequestsgetLayoutBoundsgetLayoutXgetLayoutYgetLocalToParentTransformgetLocalToSceneTransformgetNodeOrientationgetOnContextMenuRequestedgetOnDragDetectedgetOnDragDonegetOnDragDroppedgetOnDragEnteredgetOnDragExitedgetOnDragOvergetOnInputMethodTextChangedgetOnKeyPressedgetOnKeyReleasedgetOnKeyTypedgetOnMouseClickedgetOnMouseDragDonegetOnMouseDragEnteredgetOnMouseDragExitedgetOnMouseDraggedgetOnMouseDragOvergetOnMouseDragReleasedgetOnMouseEnteredgetOnMouseExitedgetOnMouseMovedgetOnMousePressedgetOnMouseReleasedgetOnRotategetOnRotationFinishedgetOnRotationStartedgetOnScrollgetOnScrollFinishedgetOnScrollStartedgetOnSwipeDowngetOnSwipeLeftgetOnSwipeRightgetOnSwipeUpgetOnTouchMovedgetOnTouchPressedgetOnTouchReleasedgetOnTouchStationarygetOnZoomgetOnZoomFinishedgetOnZoomStartedgetOpacitygetParentgetPropertiesgetPseudoClassStatesgetRotategetRotationAxisgetScaleXgetScaleYgetScaleZgetScenegetStylegetStyleableParentgetStyleClassgetTransformsgetTranslateXgetTranslateYgetTranslateZgetTypeSelectorgetUserDatagetViewOrderhasPropertieshoverPropertyidPropertyinputMethodRequestsPropertyintersectsintersectsisCacheisDisableisDisabledisFocusedisFocusTraversableisFocusVisibleisFocusWithinisHoverisManagedisMouseTransparentisPickOnBoundsisPressedisResizableisVisiblelayoutBoundsPropertylayoutXPropertylayoutYPropertylocalToParentlocalToParentlocalToParentlocalToParentlocalToParentlocalToParentTransformPropertylocalToScenelocalToScenelocalToScenelocalToScenelocalToScenelocalToScenelocalToScenelocalToScenelocalToScenelocalToScenelocalToSceneTransformPropertylocalToScreenlocalToScreenlocalToScreenlocalToScreenlocalToScreenlookuplookupAllmanagedPropertymaxHeightmaxWidthminHeightminWidthmouseTransparentPropertynodeOrientationPropertynotifyAccessibleAttributeChangedonContextMenuRequestedPropertyonDragDetectedPropertyonDragDonePropertyonDragDroppedPropertyonDragEnteredPropertyonDragExitedPropertyonDragOverPropertyonInputMethodTextChangedPropertyonKeyPressedPropertyonKeyReleasedPropertyonKeyTypedPropertyonMouseClickedPropertyonMouseDragDonePropertyonMouseDragEnteredPropertyonMouseDragExitedPropertyonMouseDraggedPropertyonMouseDragOverPropertyonMouseDragReleasedPropertyonMouseEnteredPropertyonMouseExitedPropertyonMouseMovedPropertyonMousePressedPropertyonMouseReleasedPropertyonRotatePropertyonRotationFinishedPropertyonRotationStartedPropertyonScrollFinishedPropertyonScrollPropertyonScrollStartedPropertyonSwipeDownPropertyonSwipeLeftPropertyonSwipeRightPropertyonSwipeUpPropertyonTouchMovedPropertyonTouchPressedPropertyonTouchReleasedPropertyonTouchStationaryPropertyonZoomFinishedPropertyonZoomPropertyonZoomStartedPropertyopacityPropertyparentPropertyparentToLocalparentToLocalparentToLocalparentToLocalparentToLocalpickOnBoundsPropertyprefHeightprefWidthpressedPropertypseudoClassStateChangedqueryAccessibleAttributerelocateremoveEventFilterremoveEventHandlerrequestFocusrequestFocusTraversalresizeresizeRelocaterotatePropertyrotationAxisPropertyscaleXPropertyscaleYPropertyscaleZPropertyscenePropertysceneToLocalsceneToLocalsceneToLocalsceneToLocalsceneToLocalsceneToLocalsceneToLocalsceneToLocalscreenToLocalscreenToLocalscreenToLocalsetAccessibleHelpsetAccessibleRolesetAccessibleRoleDescriptionsetAccessibleTextsetBlendModesetCachesetCacheHintsetClipsetCursorsetDepthTestsetDisablesetDisabledsetEffectsetEventDispatchersetEventHandlersetFocusedsetFocusTraversablesetHoversetIdsetInputMethodRequestssetLayoutXsetLayoutYsetManagedsetMouseTransparentsetNodeOrientationsetOnContextMenuRequestedsetOnDragDetectedsetOnDragDonesetOnDragDroppedsetOnDragEnteredsetOnDragExitedsetOnDragOversetOnInputMethodTextChangedsetOnKeyPressedsetOnKeyReleasedsetOnKeyTypedsetOnMouseClickedsetOnMouseDragDonesetOnMouseDragEnteredsetOnMouseDragExitedsetOnMouseDraggedsetOnMouseDragOversetOnMouseDragReleasedsetOnMouseEnteredsetOnMouseExitedsetOnMouseMovedsetOnMousePressedsetOnMouseReleasedsetOnRotatesetOnRotationFinishedsetOnRotationStartedsetOnScrollsetOnScrollFinishedsetOnScrollStartedsetOnSwipeDownsetOnSwipeLeftsetOnSwipeRightsetOnSwipeUpsetOnTouchMovedsetOnTouchPressedsetOnTouchReleasedsetOnTouchStationarysetOnZoomsetOnZoomFinishedsetOnZoomStartedsetOpacitysetPickOnBoundssetPressedsetRotatesetRotationAxissetScaleXsetScaleYsetScaleZsetStylesetTranslateXsetTranslateYsetTranslateZsetUserDatasetViewOrdersetVisiblesnapshotsnapshotstartDragAndDropstartFullDragstylePropertytoBacktoFronttoStringtranslateXPropertytranslateYPropertytranslateZPropertyusesMirroringviewOrderPropertyvisibleProperty

Field Detail

DEFAULT_STYLE_CLASSback to summary
private static final String DEFAULT_STYLE_CLASS
destHeightback to summary
private double destHeight
destWidthback to summary
private double destWidth
fitHeightback to summary
private StyleableDoubleProperty fitHeight

The height of the bounding box within which the source image is resized as necessary to fit. If set to a value <= 0, then the intrinsic height of the image will be used as the fitHeight.

See preserveRatio for information on interaction between image view's fitWidth, fitHeight and preserveRatio attributes.

Default Value
0
fitWidthback to summary
private StyleableDoubleProperty fitWidth

The width of the bounding box within which the source image is resized as necessary to fit. If set to a value <= 0, then the intrinsic width of the image will be used as the fitWidth.

See preserveRatio for information on interaction between image view's fitWidth, fitHeight and preserveRatio attributes.

Default Value
0
imageback to summary
private ObjectProperty<Image> image

The Image to be painted by this ImageView.

Default Value
null
imageUrlback to summary
private StringProperty imageUrl
oldImageback to summary
private Image oldImage
platformImageChangeListenerback to summary
private final AbstractNotifyListener platformImageChangeListener
preserveRatioback to summary
private StyleableBooleanProperty preserveRatio

Indicates whether to preserve the aspect ratio of the source image when scaling to fit the image within the fitting bounding box.

If set to true, it affects the dimensions of this ImageView in the following way

  • If only fitWidth is set, height is scaled to preserve ratio
  • If only fitHeight is set, width is scaled to preserve ratio
  • If both are set, they both may be scaled to get the best fit in a width by height rectangle while preserving the original aspect ratio
If unset or set to false, it affects the dimensions of this ImageView in the following way
  • If only fitWidth is set, image's view width is scaled to match and height is unchanged;
  • If only fitHeight is set, image's view height is scaled to match and height is unchanged;
  • If both are set, the image view is scaled to match both.
Note that the dimensions of this node as reported by the node's bounds will be equal to the size of the scaled image and is guaranteed to be contained within fitWidth x fitHeight bonding box.
Default Value
false
smoothback to summary
private StyleableBooleanProperty smooth

Indicates whether to use a better quality filtering algorithm or a faster one when transforming or scaling the source image to fit within the bounding box provided by fitWidth and fitHeight.

If set to true a better quality filtering will be used, if set to false a faster but lesser quality filtering will be used.

The default value depends on platform configuration.

Default Value
platform-dependent
SMOOTH_DEFAULTback to summary
public static final boolean SMOOTH_DEFAULT

Platform-dependent default value of the smooth property.

validWHback to summary
private boolean validWH
viewportback to summary
private ObjectProperty<Rectangle2D> viewport

The rectangular viewport into the image. The viewport is specified in the coordinates of the image, prior to scaling or any other transformations.

If viewport is null, the entire image is displayed. If viewport is non-null, only the portion of the image which falls within the viewport will be displayed. If the image does not fully cover the viewport then any remaining area of the viewport will be empty.

Default Value
null
xback to summary
private DoubleProperty x

The current x coordinate of the ImageView origin.

Default Value
0
yback to summary
private DoubleProperty y

The current y coordinate of the ImageView origin.

Default Value
0

Constructor Detail

ImageViewback to summary
public ImageView()

Allocates a new ImageView object.

ImageViewback to summary
public ImageView(String url)

Allocates a new ImageView object with image loaded from the specified URL.

The new ImageView(url) has the same effect as new ImageView(new Image(url)).

Parameters
url:String

the string representing the URL from which to load the image

Exceptions
NullPointerException:
if URL is null
IllegalArgumentException:
if URL is invalid or unsupported
Since
JavaFX 2.1
ImageViewback to summary
public ImageView(Image image)

Allocates a new ImageView object using the given image.

Parameters
image:Image

Image that this ImageView uses

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.

fitHeightPropertyback to summary
public final DoubleProperty fitHeightProperty()
fitWidthPropertyback to summary
public final DoubleProperty fitWidthProperty()
getClassCssMetaDataback to summary
public static List<CssMetaData<? extends Styleable, ?>> getClassCssMetaData()

Hides javafx.scene.Node.getClassCssMetaData.

Gets the CssMetaData associated with this class, which may include the CssMetaData of its superclasses.

Returns:List<CssMetaData<? extends Styleable, ?>>

the CssMetaData

Since
JavaFX 8.0
getCssMetaDataback to summary
public List<CssMetaData<? extends Styleable, ?>> getCssMetaData()

Overrides javafx.scene.Node.getCssMetaData.

Implements javafx.css.Styleable.getCssMetaData.

Doc from javafx.scene.Node.getCssMetaData.

This method should delegate to Node#getClassCssMetaData() so that a Node's CssMetaData can be accessed without the need for reflection.

Returns:List<CssMetaData<? extends Styleable, ?>>

the CssMetaData associated with this class, which may include the CssMetaData of its super classes.

Annotations
@Override
Since
JavaFX 8.0
getFitHeightback to summary
public final double getFitHeight()
getFitWidthback to summary
public final double getFitWidth()
getImageback to summary
public final Image getImage()
getViewportback to summary
public final Rectangle2D getViewport()
getXback to summary
public final double getX()
getYback to summary
public final double getY()
imagePropertyback to summary
public final ObjectProperty<Image> imageProperty()
imageUrlPropertyback to summary
private StringProperty imageUrlProperty()

The imageUrl property is set from CSS and then the image property is set from the invalidated method. This ensures that the same image isn't reloaded.

invalidateWidthHeightback to summary
private void invalidateWidthHeight()
isPreserveRatioback to summary
public final boolean isPreserveRatio()
isSmoothback to summary
public final boolean isSmooth()
preserveRatioPropertyback to summary
public final BooleanProperty preserveRatioProperty()
recomputeWidthHeightback to summary
private void recomputeWidthHeight()
setFitHeightback to summary
public final void setFitHeight(double value)
setFitWidthback to summary
public final void setFitWidth(double value)
setImageback to summary
public final void setImage(Image value)
setPreserveRatioback to summary
public final void setPreserveRatio(boolean value)
setSmoothback to summary
public final void setSmooth(boolean value)
setViewportback to summary
public final void setViewport(Rectangle2D value)
setXback to summary
public final void setX(double value)
setYback to summary
public final void setY(double value)
smoothPropertyback to summary
public final BooleanProperty smoothProperty()
updateViewportback to summary
pack-priv void updateViewport()
viewportPropertyback to summary
public final ObjectProperty<Rectangle2D> viewportProperty()
xPropertyback to summary
public final DoubleProperty xProperty()
yPropertyback to summary
public final DoubleProperty yProperty()
javafx.scene.image back to summary

private Class ImageView.StyleableProperties

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private static final CssMetaData<ImageView, Number>
private static final CssMetaData<ImageView, Number>
private static final CssMetaData<ImageView, String>
private static final CssMetaData<ImageView, Boolean>
private static final CssMetaData<ImageView, Boolean>
private static final List<CssMetaData<? extends Styleable, ?>>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

FIT_HEIGHTback to summary
private static final CssMetaData<ImageView, Number> FIT_HEIGHT
FIT_WIDTHback to summary
private static final CssMetaData<ImageView, Number> FIT_WIDTH
IMAGEback to summary
private static final CssMetaData<ImageView, String> IMAGE
PRESERVE_RATIOback to summary
private static final CssMetaData<ImageView, Boolean> PRESERVE_RATIO
SMOOTHback to summary
private static final CssMetaData<ImageView, Boolean> SMOOTH
STYLEABLESback to summary
private static final List<CssMetaData<? extends Styleable, ?>> STYLEABLES

Constructor Detail

StyleablePropertiesback to summary
private StyleableProperties()