Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 327
Chap Avatar asked Feb 13 '26 20:02

Chap


1 Answers

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

like image 183
Hovercraft Full Of Eels Avatar answered Feb 15 '26 09:02

Hovercraft Full Of Eels



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!