Java Reference
In-Depth Information
The getter methods for property
values are provided in the class, but
omitted in the UML diagram for brevity.
javafx.scene.image.Image
-error: ReadOnlyBooleanProperty
-height: ReadOnlyBooleanProperty
-width: ReadOnlyBooleanProperty
-progress: ReadOnlyBooleanProperty
Indicates whether the image is loaded correctly?
The height of the image.
The width of the image.
The approximate percentage of image's loading that is completed.
+Image(filenameOrURL: String)
Creates an
Image
with contents loaded from a file or a URL.
F
IGURE
14.12
Image
encapsulates information about images.
The getter and setter methods for property
values and a getter for property itself are provided
in the class, but omitted in the UML diagram for brevity.
javafx.scene.image.ImageView
-fitHeight: DoubleProperty
-fitWidth: DoubleProperty
-x: DoubleProperty
-y: DoubleProperty
-image: ObjectProperty<Image>
The height of the bounding box within which the image is resized to fit.
The width of the bounding box within which the image is resized to fit.
The x-coordinate of the ImageView origin.
The y-coordinate of the ImageView origin.
The image to be displayed in the image view.
Creates an
ImageView
.
Creates an
ImageView
with the specified image.
Creates an
ImageView
with image loaded from the specified file or URL.
+ImageView()
+ImageView(image: Image)
+ImageView(filenameOrURL: String)
F
IGURE
14.13
ImageView
is a node for displaying an image.
Listing 14.9 displays an image in three image views, as shown in FigureĀ 14.14.
L
ISTING
14.9
ShowImage.java
1
import
javafx.application.Application;
2
import
javafx.scene.Scene;
3
import
javafx.scene.layout.HBox;
4
import
javafx.scene.layout.Pane;
5
import
javafx.geometry.Insets;
6
import
javafx.stage.Stage;
7
import
javafx.scene.image.Image;
8
import
javafx.scene.image.ImageView;
9
10
public class
ShowImage
extends
Application {
11 @Override
// Override the start method in the Application class
12
public void
start(Stage primaryStage) {
13
// Create a pane to hold the image views
14 Pane pane =
new
HBox(
10
);
15 pane.setPadding(
new
Insets(
5
,
5
,
5
,
5
));
16
create an
HBox
Image image =
new
Image(
"
image/us.gif
"
);
create an image
add an image view to pane
17
pane.getChildren().add(
new
ImageView(image));
18
19 ImageView imageView2 =
new
ImageView(image);
20 imageView2.setFitHeight(
100
);
21 imageView2.setFitWidth(
100
);
create an image view
set image view properties
Search WWH ::
Custom Search