当点击打开的图片中的特定位置时,如何使comboBox从csv文件加载内容?

问题描述 投票:0回答:1

从csv文件加载数据不是问题。我的问题是指我需要加载数据的MouseEvent。我有一个ImageView,它显示由FileChooser和一个ComboBox选择的图像,当在图像的某个位置按下鼠标按钮时,它将从csv文件中加载一些行(例如,我可以轻松检查的矩形) mousePos.inside(rect) - >(Point mousePos = new Point((int)mouseEvent.getSceneX(),(int)mouseEvent.getSceneY())))。不幸的是我无法将mouseEvent连接到我的Combobox ......我目前的方法是:

 public void annotate(MouseEvent me) throws IOException {
comboBox.setOnMouseClicked(new EventHandler<MouseEvent>() {
                 public void handle(MouseEvent mouseEvent) {
                     int mousePosX = (int) mouseEvent.getSceneX();
                     int mousePosY = (int) mouseEvent.getSceneY();
                     opencv_core.Point mousePos = new opencv_core.Point(mousePosX,mousePosY);
                     if (mousePos.inside(rect)) {
                         List<Person> personList = null;
                         try {
                             personList = CsvToList();
                         } catch (IOException e) {
                             e.printStackTrace();
                         } 
.....
}

..... comboBox是我的fxid,它指的是用fxml文件创建的视图。我想这是错的,如果你能提供任何帮助,那将是非常好的。

java javafx combobox fxml javacv
1个回答
0
投票

你怎么认为你的鼠标指针可以在你的图像上同时在你的组合框上?你的方法没有任何意义。

而是将事件处理逻辑附加到它所属的图像视图中,然后在您加载数据时将获取的列表附加到组合框。

© www.soinside.com 2019 - 2024. All rights reserved.