重建容器列表而不滚动列表 [英] Rebuild list of containers without scrolling the list

查看:54
本文介绍了重建容器列表而不滚动列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序显示了很长的容器列表,当用户编辑其中一个容器的内容时​​,必须刷新整个列表,因为其他容器中的内容可能会更改(它们也可能会更改大小)。

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).

当前,我只是通过 getContentPane()。removeAll()来完成此操作,然后重新计算所有容器,并然后 revalidate()显示更新后的表格。但是,当我这样做时,列表将滚动回到顶部。

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.

我如何在列表中保持相同的滚动位置,例如刚刚编辑的容器的新实例与以前在屏幕上的位置相同?我知道 scrollComponentToVisible(Component),但据我所知,它不允许我将容器放置在屏幕上与刷新之前完全相同的位置。 / p>

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.

推荐答案

由于您重新构建位置可能会发生变化,因此直接调用 setScrollY()可能不会提供与我认为不可行的位置相同的位置,因为您需要的功能更接近 scrollComponentToVisible

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.

这篇关于重建容器列表而不滚动列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆