Java Reference
In-Depth Information
TextArea
provides scrolling, but often it is useful to create a
ScrollPane
object to hold an
instance of
TextArea
and let
ScrollPane
handle scrolling for
TextArea
, as follows:
// Create a scroll pane to hold text area
ScrollPane scrollPane =
new
ScrollPane(taNote);
Tip
You can place any node in a
ScrollPane
.
ScrollPane
provides vertical and
horizontal scrolling automatically if the control is too large to fit in the viewing area.
ScrollPane
We now give a program that displays an image and a short text in a label, and a long text
in a text area, as shown in Figure 16.14.
DescriptionPane
A label
showing an
image and a
text
A text area
inside a
scroll pane
F
IGURE
16.14
The program displays an image in a label, a title in a label, and text in the text area.
Here are the major steps in the program:
1. Define a class named
DescriptionPane
that extends
BorderPane
, as shown
in Listing 16.6. This class contains a text area inside a scroll pane, and a label for
displaying an image icon and a title. The class
DescriptionPane
will be reused in
later examples.
2. Define a class named
TextAreaDemo
that extends
Application
, as shown in
Listing 16.7. Create an instance of
DescriptionPane
and add it to the scene. The rela-
tionship between
DescriptionPane
and
TextAreaDemo
is shown in Figure 16.15.
javafx.scene.layout.BorderPane
javafx.application.Application
1
1
DescriptionPane
TextAreaDemo
-lblImageTitle: Label
-taDescription: TextArea
+setImageView(im: ImageView)
+setDescription(text: String)
F
IGURE
16.15
TextAreaDemo
uses
DescriptionPane
to display an image, title, and text
description of a national flag.
L
ISTING
16.6
DescriptionPane.java
1
import
javafx.geometry.Insets;
2
import
javafx.scene.control.Label;
3
import
javafx.scene.control.ContentDisplay;
Search WWH ::
Custom Search