我正在用 smack 制作一个聊天客户端。因此,登录后我将名册检索到我的 javafx 应用程序中。为了监听我的好友是否有空,我尝试使用这样的监听器:
rosterList.addListener(new ChangeListener<ObservableList<RosterDTO>>(){
@Override
public void changed(
ObservableValue<? extends ObservableList<RosterDTO>> observable,
ObservableList<RosterDTO> oldValue,
ObservableList<RosterDTO> newValue) {
rosterList = loginManager.getXmppManager().displayBuddyList();
System.out.println("x----" + rosterList.toString());
}
因此,在我输入代码后,Eclipse 返回:
The method addListener(ListChangeListener) in the type ObservableList is not applicable for the arguments (new ChangeListener>(){})
为什么会发生这种情况?我的监听器应该如何实现?
提前致谢。
最佳答案
一个ChangeListener不是ListChangeListener .
ObservableList.addListener需要一个 ListChangeListener 作为参数。
JavaFX collections tutorial详细介绍了如何使用ListChangeListeners。
关于java - 为什么我不适用于 javafx 上的参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17751425/