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:
| Modifier and Type | Class and Description |
|---|---|
| private static class |
| Modifier and Type | Field 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 | |
| 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 |
| public static final boolean | SMOOTH_DEFAULT
Platform-dependent default value of the |
| private boolean | |
| private ObjectProperty | viewport
The rectangular viewport into the image. |
| private DoubleProperty | x
The current x coordinate of the |
| private DoubleProperty | y
The current y coordinate of the |
| Access | Constructor and Description |
|---|---|
| public | |
| public | |
| public |
| Modifier and Type | Method and Description |
|---|---|
| private boolean | |
| private BaseBounds | |
| private NGNode | |
| private void | |
| public final DoubleProperty | |
| public final DoubleProperty | |
| public static List | Returns: theCssMetaDataHides javafx. Gets the |
| public List | Returns: the CssMetaData associated with this class, which may include the CssMetaData of its super classes.Overrides javafx. Implements javafx. This method should delegate to |
| public final double | |
| public final double | |
| public final Image | |
| public final Rectangle2D | |
| public final double | |
| public final double | |
| public final ObjectProperty | |
| 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 | |
| public final void | |
| public final void | |
| public final void | |
| public final void | |
| public final void | |
| public final void | |
| public final void | |
| public final BooleanProperty | |
| pack-priv void | |
| public final ObjectProperty | |
| public final DoubleProperty | |
| public final DoubleProperty |
| DEFAULT_STYLE_CLASS | back to summary |
|---|---|
| private static final String DEFAULT_STYLE_CLASS | |
| destHeight | back to summary |
|---|---|
| private double destHeight | |
| destWidth | back to summary |
|---|---|
| private double destWidth | |
| fitHeight | back 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
See
| |
| fitWidth | back 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
See
| |
| image | back to summary |
|---|---|
| private ObjectProperty<Image> image The
| |
| imageUrl | back to summary |
|---|---|
| private StringProperty imageUrl | |
| oldImage | back to summary |
|---|---|
| private Image oldImage | |
| platformImageChangeListener | back to summary |
|---|---|
| private final AbstractNotifyListener platformImageChangeListener | |
| preserveRatio | back 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
false, it affects the dimensions of this
ImageView in the following way
fitWidth x fitHeight bonding box.
| |
| smooth | back 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
If set to The default value depends on platform configuration.
| |
| SMOOTH_DEFAULT | back to summary |
|---|---|
| public static final boolean SMOOTH_DEFAULT Platform-dependent default value of the | |
| validWH | back to summary |
|---|---|
| private boolean validWH | |
| viewport | back 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
| |
| x | back to summary |
|---|---|
| private DoubleProperty x The current x coordinate of the
| |
| y | back to summary |
|---|---|
| private DoubleProperty y The current y coordinate of the
| |
| ImageView | back to summary |
|---|---|
| public ImageView() Allocates a new ImageView object. | |
| ImageView | back to summary |
|---|---|
| public ImageView(String url) Allocates a new ImageView object with image loaded from the specified URL.
The
| |
| ImageView | back to summary |
|---|---|
| public ImageView(Image image) Allocates a new ImageView object using the given image.
| |
| doComputeContains | back to summary |
|---|---|
| private boolean doComputeContains(double localX, double localY) | |
| doComputeGeomBounds | back to summary |
|---|---|
| private BaseBounds doComputeGeomBounds(BaseBounds bounds, BaseTransform tx) | |
| doCreatePeer | back to summary |
|---|---|
| private NGNode doCreatePeer() | |
| doUpdatePeer | back to summary |
|---|---|
| private void doUpdatePeer() | |
| fitHeightProperty | back to summary |
|---|---|
| public final DoubleProperty fitHeightProperty() | |
| fitWidthProperty | back to summary |
|---|---|
| public final DoubleProperty fitWidthProperty() | |
| getClassCssMetaData | back to summary |
|---|---|
| public static List Hides javafx. Gets the
| |
| getCssMetaData | back to summary |
|---|---|
| public List Overrides javafx. Implements javafx. Doc from javafx. This method should delegate to
| |
| getFitHeight | back to summary |
|---|---|
| public final double getFitHeight() | |
| getFitWidth | back to summary |
|---|---|
| public final double getFitWidth() | |
| getImage | back to summary |
|---|---|
| public final Image getImage() | |
| getViewport | back to summary |
|---|---|
| public final Rectangle2D getViewport() | |
| getX | back to summary |
|---|---|
| public final double getX() | |
| getY | back to summary |
|---|---|
| public final double getY() | |
| imageProperty | back to summary |
|---|---|
| public final ObjectProperty | |
| imageUrlProperty | back 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. | |
| invalidateWidthHeight | back to summary |
|---|---|
| private void invalidateWidthHeight() | |
| isPreserveRatio | back to summary |
|---|---|
| public final boolean isPreserveRatio() | |
| isSmooth | back to summary |
|---|---|
| public final boolean isSmooth() | |
| preserveRatioProperty | back to summary |
|---|---|
| public final BooleanProperty preserveRatioProperty() | |
| recomputeWidthHeight | back to summary |
|---|---|
| private void recomputeWidthHeight() | |
| setFitHeight | back to summary |
|---|---|
| public final void setFitHeight(double value) | |
| setFitWidth | back to summary |
|---|---|
| public final void setFitWidth(double value) | |
| setImage | back to summary |
|---|---|
| public final void setImage(Image value) | |
| setPreserveRatio | back to summary |
|---|---|
| public final void setPreserveRatio(boolean value) | |
| setSmooth | back to summary |
|---|---|
| public final void setSmooth(boolean value) | |
| setViewport | back to summary |
|---|---|
| public final void setViewport(Rectangle2D value) | |
| setX | back to summary |
|---|---|
| public final void setX(double value) | |
| setY | back to summary |
|---|---|
| public final void setY(double value) | |
| smoothProperty | back to summary |
|---|---|
| public final BooleanProperty smoothProperty() | |
| updateViewport | back to summary |
|---|---|
| pack-priv void updateViewport() | |
| viewportProperty | back to summary |
|---|---|
| public final ObjectProperty | |
| xProperty | back to summary |
|---|---|
| public final DoubleProperty xProperty() | |
| yProperty | back to summary |
|---|---|
| public final DoubleProperty yProperty() | |
| Modifier and Type | Field and Description |
|---|---|
| private static final CssMetaData | |
| private static final CssMetaData | |
| private static final CssMetaData | |
| private static final CssMetaData | |
| private static final CssMetaData | |
| private static final List |
| Access | Constructor and Description |
|---|---|
| private |
| FIT_HEIGHT | back to summary |
|---|---|
| private static final CssMetaData<ImageView, Number> FIT_HEIGHT | |
| FIT_WIDTH | back to summary |
|---|---|
| private static final CssMetaData<ImageView, Number> FIT_WIDTH | |
| IMAGE | back to summary |
|---|---|
| private static final CssMetaData<ImageView, String> IMAGE | |
| PRESERVE_RATIO | back to summary |
|---|---|
| private static final CssMetaData<ImageView, Boolean> PRESERVE_RATIO | |
| SMOOTH | back to summary |
|---|---|
| private static final CssMetaData<ImageView, Boolean> SMOOTH | |
| STYLEABLES | back to summary |
|---|---|
| private static final List<CssMetaData<? extends Styleable, ?>> STYLEABLES | |
| StyleableProperties | back to summary |
|---|---|
| private StyleableProperties() | |