JavaFX 2.2: How to force a redraw/update of a ListView

后端 未结 5 1154
悲&欢浪女
悲&欢浪女 2021-02-08 19:16

I have a ListView control in a JavaFX 2 modal dialog window.

This ListView displays DXAlias instances, the ListCells for which are manufactured by a cell factory. The m

5条回答
  •  孤城傲影
    2021-02-08 19:25

    Seems, you don't need to use updateItem method. What you need - is to store indicator of currently default cell (which is in user data now), into OblectProperty. And add a listener on this property from each cell. When value changes, reassign a style.

    But I think, such binding will call another problem - while scrolling, new cells will be created, but the old ones will not leave the binding, which can cause memory leak. So you need to add listener on cell removing from the scene. I think, it can be done by adding a listener on the parentProperty, when it becomes null - remove binding.

    UI shouldn't be forced to be updated. It is updated automaticly, when properties/rendering of existing nodes is changed. So you just need to update the appearance/property of existing nodes (cells). And not to forget, that cells can be created massively, during scrolling/rerendering, etc.

提交回复
热议问题