TableView自动更新列

时间:2019-01-07 07:08:59

标签: javafx

我正在使用TableView,在这里有一个删除行的按钮,S.no列必须自动更新

public void Delete()
{

    int myIndex = 
               MyTable.getSelectionModel().getSelectedIndex();
    System.out.println(myIndex);

    ObservableList<Parent> selectedRow, allParents;
    allParents = MyTable.getItems();

    selectedRow = MyTable.getSelectionModel().getSelectedItems();

    for(Parent parent : selectedRow)    
    {
        allParents.remove(parent);
    }


    for (int i=myIndex; ts.getCellData(i)!=null;i++)
    {


        System.out.println(i+1);
// I need here to update my column with the following values

        MyTable.getItems().forEach(item -> item.setId(k));
// I tried the above code but it display the same values in the S.no column
    }

}



// This is my TableView Model
public class Parent {

    private SimpleStringProperty ts, eo;
    private SimpleIntegerProperty id;

    Parent(Integer id, String ts, String eo){
        this.id= new SimpleIntegerProperty(id);
        this.ts= new SimpleStringProperty(ts);
        this.eo= new SimpleStringProperty(eo);
    }

    public Integer getId() {
        return id.get();
    }

    public void setId(Integer id) {
        this.id.set(id);
    }

    public String getTs() {
        return ts.get();
    }

    public void setTs(String ts) {
        this.ts.set(ts);
    }

    public String getEo() {
        return eo.get();
    }

    public void setEo(String eo) {
        this.eo.set(eo);
    }

}

期望S.no中的结果是

1
2
3
4
5
6

但是结果越来越像

1
2
3
5
6

0 个答案:

没有答案