【发布时间】:2014-09-23 17:02:12
【问题描述】:
我知道以前可能有人问过这个问题,但我无法理解这个问题,希望我们可以为一个有点棘手的界面提供完整的答案。
图形用户界面可以描述如下: 应用程序扩展了 JFrame。应用程序添加了一个 JPanel mPanel。 mPanel 添加了一个 JScrollPane ml,其中包含一个扩展 JPanel 的 MoviePanel。
JScrollPane ml 具有垂直滚动功能。我的目标是,一旦 MoviePanel 的内容发生变化,并在其上运行 revalidate(),滚动窗格不应像当前那样滚动到底部。相反,我希望它滚动到它在更改为 MoviePanel 之前的任何位置。给人一种从不滚动的感觉。
我尝试在运行 revalidate() 方法后手动设置滚动位置:
removeAll(); // Removes all components from the JPanel MoviePanel
add(mList()); // Adds a bunch of content (other JPanels) to MoviePanel
revalidate();
ml.getVerticalScrollBar().setValue(0); // Scroll to top (don't work) - and I'd like this value to be the position of the scroll before these lines started to run
但它似乎真的没有做任何事情。
如果有人可以帮助我,我将不胜感激!
【问题讨论】:
标签: java swing scrollbar jscrollpane