When you scroll a ListView
the swipe gesture triggers a Mouse Drag Event. You can set a flag, when the drag event is detected, and consume the following Mouse Clicked Event.
public class ScrollListener {
private BooleanProperty scrolling;
public ScrollListener(Node observableNode) {
scrolling = new ReadOnlyBooleanWrapper(false);
observableNode.addEventHandler(MouseEvent.DRAG_DETECTED, e -> scrolling.set(true));
observableNode.addEventFilter(MouseEvent.MOUSE_CLICKED, evt -> {
if (scrolling.get()) {
scrolling.set(false);
evt.consume();
}
});
observableNode.addEventHandler(MouseEvent.MOUSE_EXITED, e -> scrolling.set(false));
}
public ReadOnlyBooleanProperty scrollingProperty() {
return scrolling;
}
public boolean isScrolling() {
return scrolling.get();
}
}
Another possiblity is to you use Gluon's CharmListView
, which takes care of the Mouse Click Event on its own, but (until now) is not as conveniend to use as the standard ListView
, e.g. when you need to access the SelectionModel
, as you can see in this question: CharmListView SelectedItemProperty?