带事件的javaFX TableCell

时间:2015-05-11 14:25:27

标签: javafx tablecell eventhandler tablecolumn

将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。

0 个答案:

没有答案