表视图清除不清除视图 [英] Table view clear dont clear the view

查看:107
本文介绍了表视图清除不清除视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个如下定义的表视图

I have a table view defined like following

@FXML
private TableView<ModelFieldTableEntry> modelFieldsTable;

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

When the user click i reload the table with the clicked item details. Before i reload i call clear on table items

modelFieldsTable.getItems().clear();

但我看到奇怪的行为,因为假设我点击了一个项目,它有4行
< a href =https://i.stack.imgur.com/Bgxv2.png =nofollow noreferrer>

But I see strange behaviour because suppose i clicked a item and it has 4 rows

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

Now when i click on another item and i try to reload the table it looks like following. This is very strange because there should be only 1 row but the size of the rows are same like from previous click and the rest of the rows are empty besides the icons. When i click the icons nothing happens. Anybody faced such situation before. Anybody knows what might be causing this ?

我的工具def如下所示。它们只是2 TableColumn 's

My tools def looks like following. They are just 2 TableColumn's

 fieldEditColumn.setCellValueFactory(cellData -> cellData.getValue().editToolProperty());
 fieldEditColumn.setCellFactory(p -> new ColumnEditCell(......));
 fieldDeleteColumn.setCellFactory(p -> new ColumnDeleteCell(.....));
 fieldDeleteColumn.setCellValueFactory(cellData -> cellData.getValue().deleteProperty());

public class ColumnEditCell extends TableCell<ModelFieldTableEntry, Boolean> {

    private Button cellButton;

    public ColumnEditCell(....) {
        .....
        initializeHandleEvent();
    }

    private void initializeHandleEvent() {
        cellButton = new Button();
        cellButton.setGraphic(IconUtils.createIcon(FontAwesomeIcon.EDIT));

        cellButton.setOnAction(t -> {
            .....
        });
    }

    @Override
    protected void updateItem(final Boolean t, final boolean empty) {
        super.updateItem(t, empty);
        if (!empty) {
            setItem(t);
            setGraphic(cellButton);
        }
    }
}

推荐答案

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

You need to "undo" changes in case a cell becomes empty. You have not done this which results in cells that were filled but become empty later to remain unchanged. In this case you need to apply the following change to 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);
    }
}

这篇关于表视图清除不清除视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆