add Auto Scroll for JavaFX TableView - Java JavaFX

Java examples for JavaFX:Table

Description

add Auto Scroll for JavaFX TableView

Demo Code


/*/*  w ww.  ja  va2s  .c om*/
     * BurpKit - WebKit-based penetration testing plugin for BurpSuite
     * Copyright (C) 2015  Red Canari, Inc.
     *
     * This program is free software: you can redistribute it and/or modify
     * it under the terms of the GNU General Public License as published by
     * the Free Software Foundation, either version 3 of the License, or
     * (at your option) any later version.
     *
     * This program is distributed in the hope that it will be useful,
     * but WITHOUT ANY WARRANTY; without even the implied warranty of
     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     * GNU General Public License for more details.
     *
     * You should have received a copy of the GNU General Public License
     * along with this program.  If not, see <http://www.gnu.org/licenses/>.
     */
//package com.java2s;
import javafx.collections.ListChangeListener;
import javafx.scene.control.ListView;
import javafx.scene.control.TableView;

public class Main {
  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);
      }
    }));
  }

  public static <S> void addAutoScroll(final ListView<S> view) {
    if (view == null) {
      throw new NullPointerException();
    }

    view.getItems().addListener((ListChangeListener<S>) (c -> {
      c.next();
      if (c.wasAdded())
        view.scrollTo(c.getTo());
    }));
  }
}

Related Tutorials