I want to add a custom action in my new component. How to do this?
Example code:
Component
public class MyCustomComponent extends Region {
public MyCustomComponent(){
super();
this.setOnMouseClicked(new EventHandler<MouseEvent>(){
@Override
public void handle(MouseEvent event) {
/* throw my custom event here and handle it in my FXML controller - but how? :-( */
}
});
}
}
Controller
public class MyController {
@FXML protected void myCustomAction(ActionEvent event) {
// do something
}
}
FXML:
<BorderPane fx:controller="fxmlexample.MyController"
xmlns:fx="http://javafx.com/fxml">
<top>
<MyCustomComponent onAction="#myCustomAction">
</MyCustomComponent>
</top>
</BorderPane>
Thx for help