Javafx tableview auto scroll to last

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

I checked the scroll bar with the horizontal and vertical setValue () property. Is there a similar way for a table scrollbar?

+5
source share
2 answers

Check out TableView.scrollTo () outside.

+11
source

Here is a complete general 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);
        }
    }));
}
+3
source

All Articles