Java examples for JavaFX:ListView
Makes JavaFX ListView scroll on the bottom element when added.
//package com.java2s; import javafx.collections.ListChangeListener; import javafx.scene.control.ListView; public class Main { /**// w ww . ja v a2 s . c o m * Makes ListView scroll on the bottom element when added. * @param view * @param <S> */ public static <S> void addAutoScroll(final ListView<S> view) { if (view == null) { throw new NullPointerException(); } view.getItems().addListener((ListChangeListener<S>) (c -> { c.next(); final int size = view.getItems().size(); if (size > 0) { view.scrollTo(size - 1); } })); } }