Chap
Chap

Reputation: 3835

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?

Upvotes: 3

Views: 1556

Answers (2)

Hovercraft Full Of Eels
Hovercraft Full Of Eels

Reputation: 285415

It should be simple to do. Just use JList's ensureIndexIsVisible method and pass it the last index in the list (size - 1).

Upvotes: 3

risyasin
risyasin

Reputation: 1321

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

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

Upvotes: -1

Related Questions