Rebuild list of containers without scrolling the list

时光毁灭记忆、已成空白 提交于 2019-12-10 00:10:23

问题


My app shows long lists of containers and when the user edits the content one of them, the whole list must be refreshed since the content in the other containers may change (they may also change size).

Currently I do this simply by getContentPane().removeAll(), followed by recalculating all the containers, and then revalidate() to show the updated form. However, when I do this the list scrolls back to the top.

How can I keep the same scroll position in the list, eg that the new instance of the just edited container stays in the same place on the screen as before? I know scrollComponentToVisible(Component) but as far as I can see it doesn't allow me to place a container in exactly the same spot on the screen as before the refresh.


回答1:


Since you rebuilt the position might change so calling setScrollY() directly probably won't provide the same position I don't think that's doable since you need functionality that's closer to scrollComponentToVisible.



来源:https://stackoverflow.com/questions/39675988/rebuild-list-of-containers-without-scrolling-the-list

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!