ListBox, auto-scroll to the bottom, tips?


I run that every 0.5s, obeying a boolean to auto scroll to bottom

unless a user action happens to scroll up thru keyboard or mouse (at the slider), then the auto scroll to bottom will be suspended (so the user can calmly read whatever is there),

until the user scroll again to the bottom, or run some action that creates new lines on the ListBox, then the auto scroll to bottom resumes.

this requires me to set that boolean (to suspend auto bottom) in many places (that are user actions).

any better way than that?

I mean, you aren’t going to get around scrolling to the bottom when your autoscroll boolean is true. You might be able to do it without polling, though.

Create a reference to the VersionedList that is the ListBox’s model. (getModel())


if( listRef.update() && autoscroll ) {
    // scroll to bottom

It has the added benefit that you could have an in-between case where as long as no new data is coming in then the user can scroll… first new data then it autoscrolls again.

Edit: and yes I know that’s technically still polling… but at least you aren’t constantly resetting the slider.

1 Like

and also: lstbx.getSlider().getModel().createReference()
checking changes on it I dont need to deal with every user action, that is what I was looking for!
this indirect/alternate way is quite cool!

btw, I set to auto-scroll also if the slider hit the bottom thru user action.


Yep… it’s basically MVC. Done right, things just happen automagically in many cases.

1 Like