public void handle(MyEvent myEvent) {
// Logic here ...
}
}
And using lambda, this would be:
myClass.addEventHandler(MyEvent.MYEVENT_A, event -> {
// code here that can use event
}
}
See also:
• Handling JavaFX Events – 10/2013
• Event System Walk-through
JavaFX Lambda functions
With the arrival of Java 8 and the lambda function support, we now have the opportunity to
simplify many types of event handlers and other functions with lambda interfaces.
ChangeListener
The interface function is:
interface ChangeListener<T> {
void changed(ObservableValue<T> observable, T oldValue, T newValue);
}
which gives us a lambda function of:
(observable, oldValue, newValue) -> {…}
JavaFX Utilities
JavaFX provides a number of classes that don't have a visual representation but are none-the-less
vital to JavaFX operation.
JavaFX MultipleSelectionModel
This object represents what is selected within a selectable control such as a ListView or
TableView. It also defines whether or not the selection mode is single (only one thing may be
selected) or multiple (many things may be concurrently selected). The single vs multiple choice is
set by the "selectionMode" property which may have a value of either SelectionMode.SINGLE or
SelectionMode.MULTIPLE.
If there is no item selected, the returned single index is "-1".
See also:
• JavaFX ListView
• JavaFX TableView
• JavaFX TreeTableView
JavaFX Development
Page 284
Comentários a estes Manuais