【发布时间】:2017-01-17 16:56:57
【问题描述】:
我创建了一个简单的 TableView,它从数据库中获取数据,我想要的是能够使用 JavaFx 轻松更改该表的数字列的值。
但是……因为我有一些心理问题什么的,我不能让它工作。
下面是“SpinnerCell”组件,我遇到的问题是,即使在触发 commitEdit 之后,当我从 TableView 获取项目时,也没有更改任何值。我在这个更新生命周期中遗漏了什么?
import javafx.scene.control.Spinner;
import javafx.scene.control.TableCell;
public class SpinnerTableCell<S, T extends Number> extends TableCell<S, T> {
private final Spinner<T> spinner;
public SpinnerTableCell() {
this(1);
}
public SpinnerTableCell(int step) {
this.spinner = new Spinner<>(0, 100, step);
this.spinner.valueProperty().addListener((observable, oldValue, newValue) -> commitEdit(newValue));
}
@Override
protected void updateItem(T c, boolean empty) {
super.updateItem(c, empty);
if (empty || c == null) {
setText(null);
setGraphic(null);
return;
}
this.spinner.getValueFactory().setValue(c);
setGraphic(spinner);
}
}
【问题讨论】:
标签: javafx