I' trying to build an application using javafx and mvvmfx framework to compute and display CVRP Problem but when I add an event listener on a Circle, it is never triggered.
scope.subscribe("STOP_LOADED", (key, payload) -> {
stepList.clear();
stopList.clear();
Stop depot = CVRPGraph.getDepot();
stopList.add(new Circle(toUiUnit(depot.getX()), toUiUnit(depot.getY()), 3, Color.BLACK));
stopList.addAll(CVRPGraph.getClientList().stream()
.map(stop -> {
Circle circle = new Circle(toUiUnit(stop.getX()), toUiUnit(stop.getY()), 3, Color.RED);
circle.setOnMouseClicked(mouseEvent -> System.out.println(mouseEvent.getEventType().getName()));
return circle;
})
.collect(Collectors.toList()));
});
stopList is initialize like this
private final ObservableList<Circle> stopList = FXCollections.observableArrayList();
which I fullfill in the viewmodel and in the view I observe an change like this
graphViewModel.stopList().addListener((ListChangeListener<? super Circle>) change -> {
stopGroup.getChildren().clear();
stopGroup.getChildren().addAll(change.getList());
});
where stopGroup is javafx.scene.Group
@FXML
private Group stopGroup;
Circle are displayed but when I click on it nothing is print
Program screenshot What I am doing wrong ?
P.S. You can find the entire code here https://github.com/ptourneur/CapacitatedVehicleRoutingProblem but do not hesitate if you need more information thanks
The problem in your example app is a misconfigured layout. Your usage of the AnchorPane is wrong. Your "ParamView.fxml" is covering the whole app window even though it's only visible on the right side. And therefor it is also consuming all mouse events. If you remove the paramsview the clickhandlers are working as expected. For debugging you could add visual borders to your container components to see how much space they are really using. If you use AnchorPane your should normally also use AnchorPane.bottomAnchor, topAnchor and so on.