[英]How do I programmatically control the position of JScrollPane?
I have a JScrollPane
containing a JPanel
and, in turn, a JList
.我有一个
JScrollPane
包含一个JPanel
和一个JList
。 I want for the viewport to always show the end of the list (from which items are being removed or added).我希望视口始终显示列表的末尾(从中删除或添加项目)。 I can accomplish this manually by dragging the
ScrollBar
to the bottom, where it stays, just the way I want it to.我可以通过将
ScrollBar
拖到底部来手动完成此操作,就像我想要的那样。 What should I do to accomplish this automatically?我应该怎么做才能自动完成这个?
It should be simple to do.做起来应该很简单。 Just use JList's
ensureIndexIsVisible
method and pass it the last index in the list (size - 1).只需使用 JList 的
ensureIndexIsVisible
方法并将列表中的最后一个索引(大小 - 1)传递给它。
You can use "scrollto" call while after creating JScrollPane.创建 JScrollPane 后,您可以使用“scrollto”调用。
here is the link for documentation.这是文档的链接。 http://jscrollpane.kelvinluck.com/scroll_to.html
http://jscrollpane.kelvinluck.com/scroll_to.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.