Java Reference
In-Depth Information
At this point, you've built and run the “Hello Earthrise” program application, both from the command line and
using NetBeans. Before leaving this example, we show you another way to achieve the scrolling
Text
node. There is
a class in the
javafx.scene.control
package named
ScrollPane
whose purpose is to provide a scrollable view of a
node that is typically larger than the view. In addition, the user can drag the node being viewed within the scrollable
area. Figure
1-8
shows the Hello Earthrise program after being modified to use the
ScrollPane
control.
Figure 1-8.
Using the
ScrollPane
control to provide a scrollable view of the
Text
node
Notice that the move cursor is visible, signifying that the user can drag the node around the clipped area.
Note that the screenshot in Figure
1-8
is of the program running on Windows, and the move cursor has a different
appearance on other platforms. Listing 1-2 contains the relevant portion of code for this example, named
HelloScrollPaneMain.java
.
Listing 1-2.
The
HelloScrollPaneMain.java
Program
...code omitted...
// Create a ScrollPane containing the text
ScrollPane scrollPane = new ScrollPane();
scrollPane.setLayoutX(50);
scrollPane.setLayoutY(180);
scrollPane.setPrefWidth(400);
scrollPane.setPrefHeight(85);
scrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
scrollPane.setVbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
scrollPane.setPannable(true);
scrollPane.setContent(textRef);
scrollPane.setStyle("-fx-background-color: transparent;");
// Combine ImageView and ScrollPane
Group root = new Group(iv, scrollPane);
Scene scene = new Scene(root, 516, 387);
Now that you've learned some of the basics of JavaFX application development, let's examine another sample
application to help you learn more JavaFX concepts and constructs.
Search WWH ::
Custom Search