简体   繁体   English

如何在JList模型中注册更改?

[英]How to register a change in a JList Model?

I am having issues understanding which interface I need to listen to changes in a listModel. 我在理解哪个接口需要监听listModel中的更改时遇到问题。 I thought it was ListDataListener, but I can't understand the methods in it. 我以为是ListDataListener,但我无法理解其中的方法。 There are 3 methods in it and this one seems to be the one I want but I can't understand the description: 它有3种方法,这个方法似乎是我想要的方法,但我无法理解描述:

contentsChanged(ListDataEvent e) 
      Sent when the contents of the list has changed in a way that's too complex to characterize with the previous methods.

What does it mean by "too complex"? “过于复杂”是什么意思? And by "characterize with the previous methods"? 并通过“以前的方法表征”? Well, what does the whole thing mean? 那么,整个事情意味着什么? Is this the interface I want? 这是我想要的界面吗?

ListModel dispatches events to its ListDataListener listeners. ListModel将事件调度到其ListDataListener侦听器。 It's more efficient for the list model to invoke the detailed intervalAdded and intervalRemoved methods when possible. 列表模型在可能的情况下调用详细的intervalAddedintervalRemoved方法更有效。 The Listener of the list model (in this case a JList ) can use these detailed changes to make minimal changes to the visual component (ie, for intervalAdded it can just add the new row instead of redrawing the whole list). 列表模型的监听器(在这种情况下是JList )可以使用这些详细的更改来对可视组件进行最小的更改(即,对于intervalAdded它可以只添加新行而不是重绘整个列表)。

However, some changes may be too complex to be described as with just added and removed. 但是,某些更改可能过于复杂,无法添加和删除。 In this case, the list model has the option of invoking contentsChanged . 在这种情况下,列表模型可以选择调用contentsChanged When JList sees contentsChanged it will most likely refetch the entire list from the list model. JList看到contentsChanged它很可能会从列表模型中重新获取整个列表。

Yes, that's the right listener. 是的,那是正确的倾听者。

The statement means that this method is the more general one, that will cover every possible change to the list content. 该声明意味着此方法更为通用,将涵盖列表内容的每个可能的更改。 The other ones ( intervalAdded and intervalRemoved ) should be used when those specific events occur. 当这些特定事件发生时,应该使用其他的( intervalAddedintervalRemoved )。

In my practice you will always use the most general one (even with table listeners).. I guess it was supposed to be used to optimize (especially with big lists). 在我的练习中,你将始终使用最通用的一个(即使是表监听器)..我猜它应该用于优化(特别是大型列表)。

A tutorial on this listener can be found here . 可在此处找到有关此侦听器的教程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM