Java Reference
In-Depth Information
Defining a ScrollBar
The ScrollBar control, like the Slider control discussed earlier, represents a numeric value with its thumb, and enables
the user to choose a numeric value by dragging its thumb. The ScrollBar control is typically used in conjunction with
other nodes to define a new UI component, the ScrollPane and ListView serving as two examples of this. In Step 29
you interacted with the ScrollBar , shown in Figure 6-10 , to control the value of the ProgressBar directly above it.
The following snippet from Listing 6-12 contains the code that realizes the ScrollBar -related portions of this behavior:
final ScrollBar scrollBar = new ScrollBar();
scrollBar.setPrefWidth(200);
scrollBar.setMin(-1);
scrollBar.setMax(model.maxKph);
scrollBar.valueProperty().bindBidirectional(model.kph);
As with the Slider , the range of the ScrollBar is set through its min and max properties, which in this case
are -1 and the value of the maxKph instance variable located in the StarterAppModel class. Also, the value property of
the ScrollBar is bidirectionally bound to the kph property in the model, which is used for keeping the ProgressBar
updated as you experienced in Step 29. The following code snippet from Listing 6-1 contains the relevant instance
variables from our StarterAppModel class:
public double maxKph = 300.0;
public DoubleProperty kph = new SimpleDoubleProperty(0);
Using a ProgressBar
The ProgressBar control is a specialization of the ProgressIndicator that displays the progress of an operation as a
bar. The following snippet contains the code that creates the ProgressBar and keeps its progress property updated
from the relevant instance variables in the model.
final ProgressBar progressBar = new ProgressBar();
progressBar.setPrefWidth(200);
progressBar.progressProperty().bind(model.kph.divide(model.maxKph));
As a result of the bind shown in this snippet, when the kph variable in the StarterAppModel class is negative, the
progress property of the ProgressBar becomes negative. This causes the ProgressBar to assume the indeterminate
appearance that you experienced in Step 29.
Now we move away from the UI controls that graphically represent numeric values in various ranges, toward the
controls that deal with HTML and other web-related content.
Creating an HTMLEditor
The HTMLEditor control enables users to edit rich text, with its underlying data represented in HTML. As you
experienced in Step 32 of the exercise, the HTMLEditor shown in Figure 6-12 contains several tools for editing text, as
well as the editing area itself.
To create the HTMLEditor instance, our StarterApp program defines a method that we've arbitrarily named
createHtmlEditorDemoNode() , shown in Listing 6-13. This method leverages the BorderPane , HTMLEditor , and
Button classes, returning a BorderPane instance that contains the HTMLEditor and a button labeled View HTML.
 
Search WWH ::




Custom Search