0
將EventHander添加到TableCell的正確方法是什麼?javaFX TableCell with event
起初我只用了兩行
@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。
非常感謝你這麼快速的回覆。它現在有效 – user2760830