Java Reference
In-Depth Information
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.control.ComboBoxBase<T>
-value: ObjectProperty<T>
-editable: BooleanProperty
-onAction:
ObjectProperty<EventHandler<ActionEvent>>
The value selected in the combo box.
Specifies whether the combo box allows user input.
Specifies the handler for processing the action event.
javafx.scene.control.ComboBox<T>
-items: ObjectProperty<ObservableList<T>>
-visibleRowCount: IntegerProperty
The items in the combo box popup.
The maximum number of visible rows of the items in the
combo box popup.
Creates an empty combo box.
Creates a combo box with the specified items.
+ComboBox()
+ComboBox(items: ObservableList<T>)
F IGURE 16.16
ComboBox enables the user to select an item from a list of items.
ComboBox inherits from ComboBoxBase . ComboBox can fire an ActionEvent .
Whenever an item is selected, an ActionEvent is fired. ObservableList is a
subinterface of java.util.List . So you can apply all the methods defined in List
for an ObservableList . For convenience, JavaFX provides the static method
FXCollections.observableArrayList(arrayOfElements)
for
creating
an
ObservableList from an array of elements.
Listing 16.8 gives a program that lets the user view an image and a description of a coun-
try's flag by selecting the country from a combo box, as shown in FigureĀ 16.17.
ComboBox
DescriptionPane
F IGURE 16.17
Information about a country, including an image and a description of its flag,
is displayed when the country is selected in the combo box.
Here are the major steps in the program:
1. Create the user interface.
Create a combo box with country names as its selection values. Create a DescriptionPane
object (the DescriptionPane class was introduced in the preceding section). Place
the combo box at the top of the border pane and the description pane in the center of the
border pane.
2. Process the event.
Create a handler for handling action event from the combo box to set the flag title,
image, and text in the description pane for the selected country name.
 
 
Search WWH ::




Custom Search