7
votes

I want to show the last item added in the table view when appears a scroll bar. Is there any way for the same and it will be grateful if can.

I have checked scroll pane with horizontal and vertical setValue() property. Is there any similar way for the table view scroll bar?

2

2 Answers

4
votes

Here is a full generic solution:

public static <S> void addAutoScroll(final TableView<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);
        }
    }));
}