【发布时间】:2020-04-05 18:26:29
【问题描述】:
我正在尝试使用 javafx 和 mvvmfx 框架构建应用程序来计算和显示 CVRP Problem,但是当我在 Circle 上添加事件侦听器时,它永远不会被触发。
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 是这样初始化的
private final ObservableList<Circle> stopList = FXCollections.observableArrayList();
我在视图模型中填充,并在视图中观察到这样的变化
graphViewModel.stopList().addListener((ListChangeListener<? super Circle>) change -> {
stopGroup.getChildren().clear();
stopGroup.getChildren().addAll(change.getList());
});
其中 stopGroup 是 javafx.scene.Group
@FXML
private Group stopGroup;
显示圆圈,但当我点击它时,什么都没有打印
Program screenshot 我做错了什么?
附:您可以在这里找到完整的代码https://github.com/ptourneur/CapacitatedVehicleRoutingProblem,但如果您需要更多信息,请不要犹豫,谢谢
【问题讨论】:
-
请提供minimal reproducible example。比如
stopList是什么? -
没有人愿意涉足大量不相关的代码 - 将其剥离为仍然可以证明问题的最小示例(如 @Slaw 所建议的那样)并在此处发布。