2
我正在使用JavaFX编写可编辑表格我想验证输入(例如,如果验证失败,是否已存在相同的值)我想要拒绝新值。换句话说,当用户在单元格中输入新值并点击ENTER时,我会进行验证,如果失败,我想查看单元格中的旧值。TableColumn中的onEditCommit中可编辑单元格的验证
我的代码看起来非常相似,这个例子 http://java-buddy.blogspot.com/2012/04/javafx-2-editable-tableview.html
我以为我可以做这样的事情
colName.setCellFactory(trainerStringCellFactory);
colName.setOnEditCommit(
new EventHandler<TableColumn.CellEditEvent<GymTrainer, String>>() {
public void handle(TableColumn.CellEditEvent<GymTrainer, String> t) {
GymTrainer newTrainer = new GymTrainer(t.getNewValue(), trainer.getSurrname(), trainer.getRateOfPay());
newTrainer.setTrainerId(trainer.getTrainerId());
if (!updateTrainer(newTrainer)) {
// Here I would like to replace value in editable cell
}
}
}
});
有没有人有一个想法如何做到这一点,或者也许是放错了地方这样做?
你有没有找到永久的解决方案呢? – Jeevanantham