Reputation: 38152
According to the JavaFX tutorial it should be possible to register event handlers to observable properties in FXML:
Any class that defines a setOnEvent() method can be assigned an event handler in markup, as can any observable property (via an "onPropertyChange" attribute).
Now, I'm trying to register an event handler for the selected property of ToggleButton:
<ToggleButton text="%SomePane.fooButton.text" onSelectedChanged="#handleFooSelectedChanged" toggleGroup="$toggleGroup"/>
and in the controller:
@FXML
public void handleFooSelectedChanged(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
}
But I'm getting the following error:
Caused by: javafx.fxml.LoadException: Controller method "handleFooSelectedChanged" not found.
Do I have to change the method signature? Is this a bug? Or is this not supported at all?
Upvotes: 1
Views: 1234
Reputation: 24464
Your FXML-attribute is wrong! The pattern is on<PropertyName>Change
(without 'd'), not on<PropertyName>Changed
!
So this should work: onSelectedChange="#handleFooSelectedChanged"
Note: Your controller method can also look like this:
@FXML
public void handleFooSelectedChanged(BooleanProperty observable, boolean oldValue, boolean newValue);
Upvotes: 2