0

一段时间以来,我一直在尝试在胶子上使用侦听CharmListView器。它在我的项目中不起作用,所以我决定在 FIFTY STATES 应用程序上尝试一下。我添加了以下代码:

charmListView.onMouseClickedProperty().set((MouseEvent event) ->{
                            Logger.getGlobal().log(Level.INFO, "Pick: {0}", new Object[]{event.getPickResult()});
                        });

当我启动应用程序时,NO click 会触发一个MOUSE_CLICKED事件。当我稍微向下滚动以使列表标题单元格像这样完全停靠时,在此处输入图像描述

CharmListView仅在单击顶部标题单元格时触发事件。

INFO: Pick: PickResult [node = VBox@49f31558[styleClass=text-box], point = Point3D [x = 133.0, y = 13.0, z = 0.0], distance = 1067.366530964699

列表上其他任何地方的其他点击都不会触发事件。我尝试将相同的侦听器添加到法线ListView,并且MouseEvent在单击ListView. 所以现在我被卡住了,因为我无法设置监听器来获取选定的项目。

4

1 回答 1

0

The CharmListView control is mainly intended for mobile applications, where you use scroll and swipe gestures. But these gestures trigger mouse clicked or pressed events.

If the list cells contain some event handler to process the latter, the only way scroll works is by consuming them, otherwise whenever you scroll the list, the cell event handler will be processed as well, when you start scrolling.

That's the reason why setOnMouseClicked() doesn't trigger any event if you click on the listView.

For accessing the list view selection model, please refer to this question.

于 2015-12-10T09:18:47.813 回答