将EventHander添加到TableCell的正确方法是什么?
起初我只有这两行
@FXML private TableColumn EANCol;
...
EANCol.setCellValueFactory(new PropertyValueFactory<MyRow, String>("EAN"));
一切正常,直到我尝试添加活动
EventHandler eh = new EventHandler<MouseEvent>(){
@Override
public void handle(MouseEvent mouseEvent) {
if(mouseEvent.getButton().equals(MouseButton.PRIMARY)){
if(mouseEvent.getClickCount() == 2){
System.out.print("Double clicked ");
System.out.println(mouseEvent.getTarget().toString());
}
}
}
};
EANCol.setCellFactory(new Callback<TableColumn, TableCell>() {
@Override
public TableCell call(TableColumn p) {
TableCell cell = new TableCell();
cell.setOnMouseClicked(eh);
return cell;
}
});
问题:现在我可以双击它,但整列都是空的,值为null。