更新TableView而不刷新窗口?

时间:2022-05-18 00:02:28

I have this window with a few TextFields and a TableView. I have made a search engine which every time I write in the TextFields, will display a new array of the given objects which fit what ever I write in the TextFields. Now, I have tested it, and I know that the search engine works. But the problem comes when I try to update the TableView. I have tried to work my way through it, but the only fix I can think of, is to refresh the whole window every time I type something in one of the TextFields. But this is obviously not a good thing to do.

我有这个窗口,有几个TextFields和一个TableView。我创建了一个搜索引擎,每次我在TextFields中编写时,都会显示一个给定对象的新数组,这些数组符合我在TextFields中编写的内容。现在,我已经测试了它,我知道搜索引擎可以工作。但是当我尝试更新TableView时出现问题。我试图通过它,但我能想到的唯一解决方案是每次在其中一个TextFields中输入内容时刷新整个窗口。但这显然不是一件好事。

So my question is: Do you know how to refresh the list in the TableView, without refreshing the whole window? Or is there anything else I can use to visually display for example "Person" objects, make them click-able and holds pointers to the given objects?

所以我的问题是:你知道如何在不刷新整个窗口的情况下刷新TableView中的列表吗?或者还有什么我可以用来直观地显示例如“Person”对象,使它们可以点击并保存指向给定对象的指针?

Please come with any input you have, and I will be happy to either try or discuss what you have to say!

请提供您的任何意见,我将很乐意尝试或讨论您的意见!

1 个解决方案

#1


Found the issue!

发现了这个问题!

setItems(); seems to call the object.equals();

setItems();似乎调用了object.equals();

I made a misstake in my @Override of the .equals();

我在.equals()的@Override中犯了一个错误。

@Override
public boolean equals(Object obj) {
    return this.birthNo.equals(((Person) obj).getBirthNo());
}

Corrected this to:

更正为:

@Override
public boolean equals(Object obj) {
    return obj != null && this.birthNo.equals(((Person) obj).getBirthNo());
}

#1


Found the issue!

发现了这个问题!

setItems(); seems to call the object.equals();

setItems();似乎调用了object.equals();

I made a misstake in my @Override of the .equals();

我在.equals()的@Override中犯了一个错误。

@Override
public boolean equals(Object obj) {
    return this.birthNo.equals(((Person) obj).getBirthNo());
}

Corrected this to:

更正为:

@Override
public boolean equals(Object obj) {
    return obj != null && this.birthNo.equals(((Person) obj).getBirthNo());
}