Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javafx tableview auto scroll to the last

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?

like image 532
Noufal Panolan Avatar asked Feb 08 '13 18:02

Noufal Panolan


2 Answers

Check the TableView.scrollTo() out.

like image 198
Uluk Biy Avatar answered Nov 13 '22 05:11

Uluk Biy


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);
        }
    }));
}
like image 21
Vertex Avatar answered Nov 13 '22 05:11

Vertex