如何检测JavaFx双击listView



我刚刚写完一段代码,在listView上单击元素后打开它。但我希望添加一个允许用户修改该元素的功能,所以用户双击该元素进行修改,然后简单地单击它来显示他的面板。有什么解决方案吗?谢谢

在自定义CellFactory中使用setOnMouseClicked

yourListView.setCellFactory(lv -> new ListCell<YourObject>()
{
@Override
public void updateItem(YourObject item, boolean empty)
{
super.updateItem(item, empty);
if (empty) {
setText(null);
setGraphic(null);
}
else {
//do other stuff here
setOnMouseClicked(mouseClickedEvent -> {
if (mouseClickedEvent.getButton().equals(MouseButton.PRIMARY) && mouseClickedEvent.getClickCount() == 2) {
System.out.println("double clicked");                       
}
});
}
}
});

最新更新