表视图清除不清除视图

时间:2018-01-17 16:13:44

标签: javafx javafx-8 javafx-2

我的表视图定义如下

3

当用户点击我重新加载包含所点击项目详细信息的表格时。在我重新加载之前,我打电话给表项目清除

@FXML
private TableView<ModelFieldTableEntry> modelFieldsTable;

但我看到奇怪的行为,因为假设我点击了一个项目,它有4行 enter image description here

现在当我点击另一个项目并尝试重新加载表格时,它看起来像是跟随。这是非常奇怪的,因为应该只有1行,但行的大小与之前的点击相同,除了图标之外其余的行都是空的。当我点击图标时没有任何反应。以前任何人都遇到过这种情况。有人知道是什么原因引起的吗?

我的工具def看起来如下。他们只有2 modelFieldsTable.getItems().clear();

TableColumn

enter image description here

1 个答案:

答案 0 :(得分:1)

你需要&#34;撤消&#34;如果单元格变空,则更改。你还没有这样做,导致细胞被填充但后来变为空,以保持不变。在这种情况下,您需要将以下更改应用于ColumnEditCell.updateItem

@Override
protected void updateItem(final Boolean t, final boolean empty) {
    super.updateItem(t, empty);
    if (empty) {
        setGraphic(null); // remove graphic
    } else {
        // setItem(t); //already done by super.updateItem
        setGraphic(cellButton);
    }
}