<@U25U0KPFT> made it endless in both ways ```priva...
# tornadofx
c
@carlw made it endless in both ways
Copy code
private val listener = ChangeListener<Number> { _, _, nv ->
                if ( userData != null) {
                    curIndex = index
                    val pos = listView.height - this.height - nv.toDouble()
                    val rowsOnView = (listView.height/this.height).toInt()
                    val firstPos = (pos-this.height*rowsOnView).toInt()
                    if (index == 0 && ((firstPos > 0 && firstPos<this.height/2) || (firstPos < 0 && firstPos > -(this.height/2)))){
                        runAsync {
                            getPrevMessages()
                        } ui {
                            records.addAll(0, it)
                            listView.scrollTo(index+50)
                        }
                    } else if ( (userData as ScrollableItemWrapper).lastItem && pos > 0 && (pos < this.height/4) && index+1 == maxRange*50) {
                        runAsync {
                            getNextMessages()
                        } ui {
                            records.addAll( it )
                            listView.scrollTo(index+1-rowsOnView)
                        }
                    }
                }
            }