简体   繁体   中英

How do I programmatically control the position of JScrollPane?

I have a JScrollPane containing a JPanel and, in turn, a 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. 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).

You can use "scrollto" call while after creating JScrollPane.

here is the link for documentation. http://jscrollpane.kelvinluck.com/scroll_to.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM